Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jmDesktop - 10 Jul 2007 22:09 GMT
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.ListViewItem[]"))
               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.ListViewItem[]"))
               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;
           }
       }
Nicholas Paldino [.NET/C# MVP] - 10 Jul 2007 22:33 GMT
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?

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.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
[quoted text clipped - 92 lines]
>            }
>        }
jmDesktop - 11 Jul 2007 14:04 GMT
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.com> wrote:
>     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
[quoted text clipped - 106 lines]
>
> - Show quoted text -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.