excel实现拖放导入datagridview。通过打开对话框导入excel文件到datagridview,这个我实现了。
请教,我想直接把excel文件通过拖放方式导入datagridview如何实现?
请教,我想直接把excel文件通过拖放方式导入datagridview如何实现?
解决方案 »
- 大批量数据验证插入问题
- 救命。。。关于对路径访问被拒绝。。。。高手进了呀!!搞了我一天
- WinForm中如何实现类似asp.net中的母版页的效果?
- vs2005使用皮肤控件,代码怎么写
- sql2000 重装时出现存在挂起文件,怎么办?
- DataGridView绑定数据表后列的顺序混乱?
- 最近用了几天时间做了一个资料管理程序,发上来看看。
- DataGridView中数据的获取 很急哦,我在线等哦
- 数据库备份问题,不能备份到系统盘
- 关于用C#病毒的问题!(感兴趣的请进)!大家一起进步
- 一万条数据记录存入Excel如何实现秒杀
- 我有两个窗体form1和form2,怎么在form2中点击按钮增加form1中ImageList1里面的图片,然后绑定到form1中的listview上面。
参考:WINFORM实现的用于拖放操作和文件复制小功能
private void ExBtnExecute_ClickEvent(object sender, EventArgs e)
{
ExBtnExecute.CtlEnabled = false;
for (int i = 0; i < lstFilePath.Items.Count; i++)
{
Application.DoEvents();
lstFilePath.SetSelected(i, true);
//如果当前字符串是一个目录则.
if (Directory.Exists(lstFilePath.Items[i].ToString()))
{
CopyDirectory(lstFilePath.Items[i].ToString(), txtSelDrive.Text +"\\"+ Path.GetFileName(lstFilePath.Items[i].ToString()));
lstFilePath.Items[i] = "复制完成";
}
else
{
if (!File.Exists(lstFilePath.Items[i].ToString())) continue; //如果文件不存在继续下一个循环
File.Copy(lstFilePath.Items[i].ToString(), txtSelDrive.Text + "\\" + Path.GetFileName(lstFilePath.Items[i].ToString()));
lstFilePath.Items[i] = "复制完成";
}
}
lstFilePath.Items.Clear();
ExBtnExecute.CtlEnabled = true;
}
private void txtSelDrive_DoubleClick(object sender, EventArgs e)
{
FolderSelDialog.ShowDialog(this);
txtSelDrive.Text = FolderSelDialog.SelectedPath;
}
/**//// <summary>
/// 复制一个目录下的所有文件或目录到一个新的目录下
/// </summary>
/// <param name="sourcePath">源目录路径</param>
/// <param name="destPath">目标目录路径</param>
private void CopyDirectory(string sourcePath, string destPath)
{
try
{
//如果目标路径没有以\结尾则加之
if (destPath[destPath.Length - 1] != Path.DirectorySeparatorChar)
{
destPath += Path.DirectorySeparatorChar;
}
if (!Directory.Exists(destPath))
{
Directory.CreateDirectory(destPath);
}
string[] fileList = Directory.GetFileSystemEntries(sourcePath);
foreach (string file in fileList)
{
//如果是一个目录则
if (Directory.Exists(file))
{
CopyDirectory(file, destPath + Path.GetFileName(file));
}
else
{
File.Copy(file, destPath + Path.GetFileName(file),true);
}
}
}
catch(IOException ioe)
{
MessageBox.Show(ioe.Message, "复制文件时出错", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}