拖放工作但也从相同的网格 Winforms C# .NET Framework 下降
drag and drop works but also drops from and to same grid Winforms C# .NET Framework
我实现了拖放操作并且一切正常,除了我可以从网格中拖放到复制文件的同一网格中。我试图查看控件或数据源的类型,但似乎无法弄清楚。我在 if 语句中尝试 File.Exists(file) 但没有成功
我试过的
_attachmentGrid.DragEnter += (s, e) =>
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
};
_attachmentGrid.DragDrop += (s, e) =>
{
//var newPath = Directory.GetCurrentDirectory();
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files != null)
{
foreach (string file in files)
{
string fileName = Path.GetFileName(file);
AttachFile(file);
}
}
};
_attachmentGrid.MouseDown += (s, e) =>
{
byte[] data = GetData(_selection.SingleSelection);
string fileName = _selection.SingleSelection.Entity.FileAttachment.AttachmentName;
var list = new StringCollection();
list = _manager.DragAttachment(data, fileName);
DataObject dataObject = new DataObject();
dataObject.SetFileDropList(list);
_attachmentGrid.DoDragDrop(dataObject, DragDropEffects.Move | DragDropEffects.Copy);
};```
Thank you
最后在 mousedown 事件中放置了一个标签,并在拖放事件中检查标签是否为真,然后不附加解决了我的问题的文件。
我实现了拖放操作并且一切正常,除了我可以从网格中拖放到复制文件的同一网格中。我试图查看控件或数据源的类型,但似乎无法弄清楚。我在 if 语句中尝试 File.Exists(file) 但没有成功
我试过的
_attachmentGrid.DragEnter += (s, e) =>
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
};
_attachmentGrid.DragDrop += (s, e) =>
{
//var newPath = Directory.GetCurrentDirectory();
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files != null)
{
foreach (string file in files)
{
string fileName = Path.GetFileName(file);
AttachFile(file);
}
}
};
_attachmentGrid.MouseDown += (s, e) =>
{
byte[] data = GetData(_selection.SingleSelection);
string fileName = _selection.SingleSelection.Entity.FileAttachment.AttachmentName;
var list = new StringCollection();
list = _manager.DragAttachment(data, fileName);
DataObject dataObject = new DataObject();
dataObject.SetFileDropList(list);
_attachmentGrid.DoDragDrop(dataObject, DragDropEffects.Move | DragDropEffects.Copy);
};```
Thank you
最后在 mousedown 事件中放置了一个标签,并在拖放事件中检查标签是否为真,然后不附加解决了我的问题的文件。