CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Creating a toolbox type List

    Quote Originally Posted by rbettes View Post
    Is there any way I can add an icon as well for each item.
    Yes. For that purpose, you first have to add one or two image lists for the large and/or small icons to the form. (Actually, I think, you can define the image lists anywhere where they are in scope, but to the from you can simply drag them from the toolbox.) After you have filled the image list(s) with Icons, you simply set up the ListViewItem::ImageIndex property of the items. Et viola!

    As I had no specific icons at hand, I have simply used the app's default icon provided by the IDE. Doesn't look nice, but demonstrates the principle. I have attached a screenshot of the testing app, where the View property of the list view has been set to SmallIcon. As you can see, the list view even hast categories, though they are not collapsable.

    I have also implemented a simple drag & drop that allows me to drag items to the list box on the left side of the form, where then the item's Text property is added. Here are the event handlers involved:

    Code:
      // Event handlers:
    
      private:
        System::Void listView1_ItemDrag(System::Object^  sender, System::Windows::Forms::ItemDragEventArgs^  e)
        {
          DoDragDrop( e->Item, DragDropEffects::Copy );
        }
    
        System::Void listBox1_DragEnter(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e)
        {
          if (e->Data->GetDataPresent("System.Windows.Forms.ListViewItem"))
            e->Effect = DragDropEffects::All;
          else
            e->Effect = DragDropEffects::None;
        }
    
        System::Void listBox1_DragDrop(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e)
        {
          listBox1->Items->Add(((ListViewItem ^)e->Data->GetData("System.Windows.Forms.ListViewItem"))->Text);
        }
    You see it's no big deal, though it took me some time to set it up, as I did it the first time.

    What I couldn't get to work yet are the item tool tips, though.

    HTH
    Attached Images Attached Images

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

Featured