adrianjohnson
Programmer
Hi all,
I've implemented a drag and drop facility on a ListView (WinForms) application. The drag and drop itself works fine, as I write to the console the name of the file to be dropped.
However, my list view shows it's items in detail view (just 2 columns) and they're all bunched together in groups. I can get the name of the group, but cannot add the new drag-drop item into the group. Any ideas?
Here is some of the code:
Many thanks,
Adrian Johnson
Adrian Johnson
I've implemented a drag and drop facility on a ListView (WinForms) application. The drag and drop itself works fine, as I write to the console the name of the file to be dropped.
However, my list view shows it's items in detail view (just 2 columns) and they're all bunched together in groups. I can get the name of the group, but cannot add the new drag-drop item into the group. Any ideas?
Here is some of the code:
Code:
private void listMain_DragEnter(object sender, DragEventArgs e)
{
// Drag-drop operation for list view.
// User is dragging a file into the tree view.
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void listMain_DragDrop(object sender, DragEventArgs e)
{
// Drag-drop operation for list view.
// Get the name of the file being dropped in.
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
FileInfo newFile;
string fileName = "";
for (int i = 0; i < s.Length; i++)
{
newFile = new FileInfo(s[i]);
fileName = newFile.ToString();
}
Console.WriteLine(fileName.ToString());
if (currentGroup != "")
{
// Add the file to the list view.
int startIndex = fileName.LastIndexOf(@"\");
string myFile = fileName.Substring(startIndex + 1); ;
ListViewItem listItem = new ListViewItem(myFile, currentGroup);
listItem.Tag = fileName.ToString();
listItem.SubItems.Add(File.GetLastWriteTime(fileName).ToString());
listMain.Items.Add(listItem);
}
}
Many thanks,
Adrian Johnson
Adrian Johnson