473,789 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ItemD rag(object sender,
ItemDragEventAr gs e)
{ int max = listView1.Selec tedItems.Count;
ListViewItem [] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView1.Selec tedItems)
{
myItems[i] = myItem;
i+=1;
}
listView1.DoDra gDrop(new
DataObject("Sys tem.Windows.For ms.ListViewItem[]", myItems),
DragDropEffects .Move);
}

private void listView2_DragE nter(object sender, DragEventArgs
e)
{
if
(e.Data.GetData Present("System .Windows.Forms. ListViewItem[]"))
e.Effect = DragDropEffects .Move;
else
{
e.Effect = DragDropEffects .None;
}
}

private void listView2_DragD rop(object sender, DragEventArgs
e)
{
ListView.Select edListViewItemC ollection myList
= this.listView1. SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView2.Items .Add(myItem.Tex t);
listView1.Items .Remove(listVie w1.SelectedItem s[i]);
i += 1;
}
}
//***
private void listView2_ItemD rag(object sender,
ItemDragEventAr gs e)
{
int max = listView2.Selec tedItems.Count;
ListViewItem[] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView2.Selec tedItems)
{
myItems[i] = myItem;
i += 1;
}
listView2.DoDra gDrop(new
DataObject("Sys tem.Windows.For ms.ListViewItem[]", myItems),
DragDropEffects .Move);
}

private void listView1_DragE nter(object sender, DragEventArgs
e)
{
if
(e.Data.GetData Present("System .Windows.Forms. ListViewItem[]"))
e.Effect = DragDropEffects .Move;
else
{
e.Effect = DragDropEffects .None;
}
}

private void listView1_DragD rop(object sender, DragEventArgs
e)
{

ListView.Select edListViewItemC ollection myList=
this.listView2. SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView1.Items .Add(myItem.Tex t);
listView2.Items .Remove(listVie w2.SelectedItem s[i]);
i += 1;
}
}

Jul 10 '07 #1
2 3749
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.co m

"jmDesktop" <ne***********@ gmail.comwrote in message
news:11******** *************@o 61g2000hsh.goog legroups.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_ItemD rag(object sender,
ItemDragEventAr gs e)
{ int max = listView1.Selec tedItems.Count;
ListViewItem [] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView1.Selec tedItems)
{
myItems[i] = myItem;
i+=1;
}
listView1.DoDra gDrop(new
DataObject("Sys tem.Windows.For ms.ListViewItem[]", myItems),
DragDropEffects .Move);
}

private void listView2_DragE nter(object sender, DragEventArgs
e)
{
if
(e.Data.GetData Present("System .Windows.Forms. ListViewItem[]"))
e.Effect = DragDropEffects .Move;
else
{
e.Effect = DragDropEffects .None;
}
}

private void listView2_DragD rop(object sender, DragEventArgs
e)
{
ListView.Select edListViewItemC ollection myList
= this.listView1. SelectedItems;
int i = 0;

foreach (ListViewItem myItem in myList)
{
listView2.Items .Add(myItem.Tex t);
listView1.Items .Remove(listVie w1.SelectedItem s[i]);
i += 1;
}
}
//***
private void listView2_ItemD rag(object sender,
ItemDragEventAr gs e)
{
int max = listView2.Selec tedItems.Count;
ListViewItem[] myItems = new ListViewItem[max];
int i = 0;

foreach (ListViewItem myItem in listView2.Selec tedItems)
{
myItems[i] = myItem;
i += 1;
}
listView2.DoDra gDrop(new
DataObject("Sys tem.Windows.For ms.ListViewItem[]", myItems),
DragDropEffects .Move);
}

private void listView1_DragE nter(object sender, DragEventArgs
e)
{
if
(e.Data.GetData Present("System .Windows.Forms. ListViewItem[]"))
e.Effect = DragDropEffects .Move;
else
{
e.Effect = DragDropEffects .None;
}
}

private void listView1_DragD rop(object sender, DragEventArgs
e)
{

ListView.Select edListViewItemC ollection myList=
this.listView2. SelectedItems;
int i = 0;

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

listView1.Items .Add(myItem.Tex t, myItem.ImageInd ex);

On Jul 10, 5:33 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.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.c om

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

news:11******** *************@o 61g2000hsh.goog legroups.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_ItemD rag(object sender,
ItemDragEventAr gs e)
{ int max = listView1.Selec tedItems.Count;
ListViewItem [] myItems = new ListViewItem[max];
int i = 0;
foreach (ListViewItem myItem in listView1.Selec tedItems)
{
myItems[i] = myItem;
i+=1;
}
listView1.DoDra gDrop(new
DataObject("Sys tem.Windows.For ms.ListViewItem[]", myItems),
DragDropEffects .Move);
}
private void listView2_DragE nter(object sender, DragEventArgs
e)
{
if
(e.Data.GetData Present("System .Windows.Forms. ListViewItem[]"))
e.Effect = DragDropEffects .Move;
else
{
e.Effect = DragDropEffects .None;
}
}
private void listView2_DragD rop(object sender, DragEventArgs
e)
{
ListView.Select edListViewItemC ollection myList
= this.listView1. SelectedItems;
int i = 0;
foreach (ListViewItem myItem in myList)
{
listView2.Items .Add(myItem.Tex t);
listView1.Items .Remove(listVie w1.SelectedItem s[i]);
i += 1;
}
}
//***
private void listView2_ItemD rag(object sender,
ItemDragEventAr gs e)
{
int max = listView2.Selec tedItems.Count;
ListViewItem[] myItems = new ListViewItem[max];
int i = 0;
foreach (ListViewItem myItem in listView2.Selec tedItems)
{
myItems[i] = myItem;
i += 1;
}
listView2.DoDra gDrop(new
DataObject("Sys tem.Windows.For ms.ListViewItem[]", myItems),
DragDropEffects .Move);
}
private void listView1_DragE nter(object sender, DragEventArgs
e)
{
if
(e.Data.GetData Present("System .Windows.Forms. ListViewItem[]"))
e.Effect = DragDropEffects .Move;
else
{
e.Effect = DragDropEffects .None;
}
}
private void listView1_DragD rop(object sender, DragEventArgs
e)
{
ListView.Select edListViewItemC ollection myList=
this.listView2. SelectedItems;
int i = 0;
foreach (ListViewItem myItem in myList)
{
listView1.Items .Add(myItem.Tex t);
listView2.Items .Remove(listVie w2.SelectedItem s[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
1924
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 painting in the listview is the image delete, I supose that the problem is that the image exist in the imagelist, in order to solve this problem I clear the imagelist and add all the images captured, but i have another problem now, some time when I...
1
6295
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 the dragged item: private void listView2_GiveFeedback ( object sender, System.Windows.Forms.GiveFeedbackEventArgs e )
2
4019
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 inbetween the 2 listboxes so i can tell when im dragging over the form. Im stuck on when i dragenter into the 2nd listbox, how can i figure out what position their mouse is over, and what item is at that x and y position? If anybody has any...
0
1840
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 painting in the listview is the image delete, I supose that the problem is that the image exist in the imagelist, in order to solve this problem I clear the imagelist and add all the images captured, but i have another problem now, some time when I...
3
10600
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
1
4647
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 in my code I do the following to add items to the ListView. lvi = New ListViewItem With lvi .Text = "xxxxx" .SubItems.Add("yyyy") .ImageIndex = 1
2
9711
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 am not able to drag the text or image from the picturebox to the listview. In the listview_dragenter function, I have e.Effects = DragDropEffects.Copy (I have also tried e.Effects = DragDropEffects.Move, but it does not help either), which is...
1
5378
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchimpdragdrop.asp It works fine, but I have another problem. I want to create functionality like a Windows Explorer. This means, if I select some items from list view No 1 and drag&drop this to the list view No 2, then I want to mark automatically
0
2180
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 properties and methods. I have set AllowDrop to true, and have all of the Drag* events written. In addition, the listview is in the detailed view. A simple explanation of what I want to do is to drag a file from the desktop or explorer into my...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.