473,387 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 3733
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.