hi...
actually i using 2 list view boxes. for box a i load multipitures by using array. now . need to drag and drop pictures from box a to box b. that drag drop can be single picture and can be multi pictures at a time......so i wrote code to drag drop....it looks like working but......cannot see those draged pictures in box B.....
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
this.listView1.DoDragDrop(this.listView1.SelectedItems[0], DragDropEffects.Copy);
}
private void listView2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListViewItem)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
*************************************************************
over here i count how many items user select and creat array size acording to that number.
********************************************************
private void listView2_DragDrop(object sender, DragEventArgs e)
{
object[] array = new object[listView1.SelectedItems.Count];
listView1.SelectedItems.CopyTo(array, 0);
int count;
count = array.Length;
}
private void listView2_ItemDrag(object sender, ItemDragEventArgs e)
{
this.listView2.DoDragDrop(this.listView2.SelectedItems[0], DragDropEffects.All);
}
private void listView1_DragDrop(object sender, DragEventArgs e)
{
ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
if (item != null)
{
Point pt = this.listView1.PointToClient(new Point(e.X, e.Y));
ListViewItem hoveritem = this.listView1.GetItemAt(pt.X, pt.Y);
if (hoveritem != null)
{
hoveritem.Text = item.Text;
}
}
}
private void listView1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListViewItem)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
can any one HELP ME........
asela WijesooriyaPosted Feb 21, 2009, 2:01 AM
hi thx for repl but it couldn't work......bcz i use array....its telling about tree node....actually im not pro in programming.....beginning stage....actually i want to do....i already created array and loaded pictures in to that array..lets say array A..so now i need to copy selected items to another array..(array B)...and array B already created.....too....but array is null....i need to coppy selected items from array A copy to array B.... and show that array in listview box......
i wrote code....can just help me to check whats wrong with this code.......
int
i = 0; ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem; string[] array = new string[listView1.SelectedItems.Count];listView1.SelectedItems.CopyTo(array, 0);
this.listView2.Items.Add(array[i],i );asela WijesooriyaPosted Feb 20, 2009, 10:28 AM
Mahesh ChandPosted Feb 20, 2009, 10:22 AM
Here are some articles with source code on Drag Drop in ListView and in general:
Drag and Drop operations in Windows can be achieved using 3 simple events - DragEnter, DragLeave, and DragDrop.
I've had a couple inquiries on how to do drag and drop in .NET again, so I've put together a simple app for dragging text from a TreeView to a TreeView and a TreeView to a ListBox.
The attached source code is a C# application that demonstrates the drag and drop of a Windows control within a container.
To allow your program to accept files using the drag and drop, you must first pick a control that you wish to be able to accept them.
Drag and Drop in C# has been a question on the UseNet and many websites on C# so I have decided to tackle the problem here. This is an update of the directory tree component download on this web site.