Results 1 to 2 of 2

Thread: ListView drag data

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    ListView drag data

    I'm trying to drag a ListViewItem out of a ListView, and then drop it on another ListView. Having troubles retrieving the ListViewItem. It works fine if the data is text (like all the examples use). Even though GetDataPresent seems to indicate that the data is a ListViewItem, for the life of me, I can't figure out the syntax to retrieve the ListViewItem.

    Am I missing something, or is this just not possible?

  2. #2

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Thanks to some VB.NET code I found here, I can pass my ListViewItem object and retrieve it. Some relevant code:

    PHP Code:
            private void lvActiveOfficers_ItemDrag(object senderSystem.Windows.Forms.ItemDragEventArgs e)
            {
                
    lvActiveOfficers.DoDragDrop(e.ItemDragDropEffects.Copy);
            }

            private 
    void lvActiveUnits_DragOver(object senderSystem.Windows.Forms.DragEventArgs e)
            {
                if (
    e.Data.GetDataPresent("System.Windows.Forms.ListViewItem"))
                {
                    
    e.Effect DragDropEffects.Copy;
                }
                else
                {
                    
    e.Effect DragDropEffects.None;
                }
            }

            private 
    void lvActiveUnits_DragDrop(object senderSystem.Windows.Forms.DragEventArgs e)
            {
                
    ListViewItem lvItem = (System.Windows.Forms.ListViewItem)e.Data.GetData("System.Windows.Forms.ListViewItem");
                
    MessageBox.Show(lvItem.SubItems.Count.ToString());
            } 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width