472,989 Members | 3,047 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 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 3706
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
1
by: VR | last post by:
I am trying to use a custom cursor during drag-drop operation between 2 ListViews. So, I have a code that at the time GiveFeedback() is called creates a new cursor based on the icon and text of...
2
by: murl | last post by:
Im starting on a application that will map fields from an excel file to fields of a sql table for a very small integration project. I have enabled drag and drop on the source listbox, and the form...
0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
1
by: Steve | last post by:
OK, I am stumped. I cannot for the life of me get images to show in ListView items while the view is set to Details. I create an ImageList, set the SmallImageList to point to the ImageList, then...
2
by: TarheelsFan | last post by:
I am having problems with drag and drop into a listview. I am able to drag and drop items from within the listview, as well as drag items from the listview and drop into a picturebox. However, I...
1
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: ...
0
by: jawilson | last post by:
Hello, I am trying to use drag-n-drop for a listview control in my program. I created a new listview control class (just call it MyListView) that inherits from ListView, and creates a few new...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.