471,337 Members | 835 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

How do I drag and drop the listview imagelist with the text?

I have two listview controls. I have three items of text. I can drag
and drop the listview items between each other, back and forth. But
the images from the imagelist do not copy over from listview1 to
listview2, only the text does. Both listviews have their
smallimagelist as the single imagelist I have. Here is my code and
thank you for any help.

private void listView1_ItemDrag(object sender,
ItemDragEventArgs e)
{ int max = listView1.SelectedItems.Count;
ListViewItem [] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView1.SelectedItems)
{
myItems[i] = myItem;
i+=1;
}
listView1.DoDragDrop(new
DataObject("System.Windows.Forms.ListViewItem[]", myItems),
DragDropEffects.Move);
}

private void listView2_DragEnter(object sender, DragEventArgs
e)
{
if
(e.Data.GetDataPresent("System.Windows.Forms.ListV iewItem[]"))
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}

private void listView2_DragDrop(object sender, DragEventArgs
e)
{
ListView.SelectedListViewItemCollection myList
= this.listView1.SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView2.Items.Add(myItem.Text);
listView1.Items.Remove(listView1.SelectedItems[i]);
i += 1;
}
}
//***
private void listView2_ItemDrag(object sender,
ItemDragEventArgs e)
{
int max = listView2.SelectedItems.Count;
ListViewItem[] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView2.SelectedItems)
{
myItems[i] = myItem;
i += 1;
}
listView2.DoDragDrop(new
DataObject("System.Windows.Forms.ListViewItem[]", myItems),
DragDropEffects.Move);
}

private void listView1_DragEnter(object sender, DragEventArgs
e)
{
if
(e.Data.GetDataPresent("System.Windows.Forms.ListV iewItem[]"))
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}

private void listView1_DragDrop(object sender, DragEventArgs
e)
{

ListView.SelectedListViewItemCollection myList=
this.listView2.SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView1.Items.Add(myItem.Text);
listView2.Items.Remove(listView2.SelectedItems[i]);
i += 1;
}
}

Jul 10 '07 #1
2 3588
I wouldn't just try and place the ListViewItem onto the clipboard.
Chances are that the image isn't being serialized to the clipboard and
that's why you aren't getting the image on the other side.

Rather, why not create a structure/class which has the information you
need (text, index in the image list) and then recreate a new ListViewItem on
the other side?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jmDesktop" <ne***********@gmail.comwrote in message
news:11*********************@o61g2000hsh.googlegro ups.com...
>I have two listview controls. I have three items of text. I can drag
and drop the listview items between each other, back and forth. But
the images from the imagelist do not copy over from listview1 to
listview2, only the text does. Both listviews have their
smallimagelist as the single imagelist I have. Here is my code and
thank you for any help.

private void listView1_ItemDrag(object sender,
ItemDragEventArgs e)
{ int max = listView1.SelectedItems.Count;
ListViewItem [] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView1.SelectedItems)
{
myItems[i] = myItem;
i+=1;
}
listView1.DoDragDrop(new
DataObject("System.Windows.Forms.ListViewItem[]", myItems),
DragDropEffects.Move);
}

private void listView2_DragEnter(object sender, DragEventArgs
e)
{
if
(e.Data.GetDataPresent("System.Windows.Forms.ListV iewItem[]"))
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}

private void listView2_DragDrop(object sender, DragEventArgs
e)
{
ListView.SelectedListViewItemCollection myList
= this.listView1.SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView2.Items.Add(myItem.Text);
listView1.Items.Remove(listView1.SelectedItems[i]);
i += 1;
}
}
//***
private void listView2_ItemDrag(object sender,
ItemDragEventArgs e)
{
int max = listView2.SelectedItems.Count;
ListViewItem[] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView2.SelectedItems)
{
myItems[i] = myItem;
i += 1;
}
listView2.DoDragDrop(new
DataObject("System.Windows.Forms.ListViewItem[]", myItems),
DragDropEffects.Move);
}

private void listView1_DragEnter(object sender, DragEventArgs
e)
{
if
(e.Data.GetDataPresent("System.Windows.Forms.ListV iewItem[]"))
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}

private void listView1_DragDrop(object sender, DragEventArgs
e)
{

ListView.SelectedListViewItemCollection myList=
this.listView2.SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView1.Items.Add(myItem.Text);
listView2.Items.Remove(listView2.SelectedItems[i]);
i += 1;
}
}
Jul 10 '07 #2
I amended to this line and it worked:

listView1.Items.Add(myItem.Text, myItem.ImageIndex);

On Jul 10, 5:33 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
I wouldn't just try and place the ListViewItem onto the clipboard.
Chances are that the image isn't being serialized to the clipboard and
that's why you aren't getting the image on the other side.

Rather, why not create a structure/class which has the information you
need (text, index in the image list) and then recreate a new ListViewItem on
the other side?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"jmDesktop" <needin4mat...@gmail.comwrote in message

news:11*********************@o61g2000hsh.googlegro ups.com...
I have two listview controls. I have three items of text. I can drag
and drop the listview items between each other, back and forth. But
the images from the imagelist do not copy over from listview1 to
listview2, only the text does. Both listviews have their
smallimagelist as the single imagelist I have. Here is my code and
thank you for any help.
private void listView1_ItemDrag(object sender,
ItemDragEventArgs e)
{ int max = listView1.SelectedItems.Count;
ListViewItem [] myItems = new ListViewItem[max];
int i = 0;
foreach (ListViewItem myItem in listView1.SelectedItems)
{
myItems[i] = myItem;
i+=1;
}
listView1.DoDragDrop(new
DataObject("System.Windows.Forms.ListViewItem[]", myItems),
DragDropEffects.Move);
}
private void listView2_DragEnter(object sender, DragEventArgs
e)
{
if
(e.Data.GetDataPresent("System.Windows.Forms.ListV iewItem[]"))
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}
private void listView2_DragDrop(object sender, DragEventArgs
e)
{
ListView.SelectedListViewItemCollection myList
= this.listView1.SelectedItems;
int i = 0;
foreach (ListViewItem myItem in myList)
{
listView2.Items.Add(myItem.Text);
listView1.Items.Remove(listView1.SelectedItems[i]);
i += 1;
}
}
//***
private void listView2_ItemDrag(object sender,
ItemDragEventArgs e)
{
int max = listView2.SelectedItems.Count;
ListViewItem[] myItems = new ListViewItem[max];
int i = 0;
foreach (ListViewItem myItem in listView2.SelectedItems)
{
myItems[i] = myItem;
i += 1;
}
listView2.DoDragDrop(new
DataObject("System.Windows.Forms.ListViewItem[]", myItems),
DragDropEffects.Move);
}
private void listView1_DragEnter(object sender, DragEventArgs
e)
{
if
(e.Data.GetDataPresent("System.Windows.Forms.ListV iewItem[]"))
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}
private void listView1_DragDrop(object sender, DragEventArgs
e)
{
ListView.SelectedListViewItemCollection myList=
this.listView2.SelectedItems;
int i = 0;
foreach (ListViewItem myItem in myList)
{
listView1.Items.Add(myItem.Text);
listView2.Items.Remove(listView2.SelectedItems[i]);
i += 1;
}
}- Hide quoted text -

- Show quoted text -

Jul 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Silvia | last post: by
1 post views Thread by VR | last post: by
reply views Thread by Silvia | last post: by
3 posts views Thread by VB Programmer | last post: by
1 post views Thread by Steve | last post: by
2 posts views Thread by TarheelsFan | last post: by
reply views Thread by jawilson | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.