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

Thread: Creating a toolbox type List

  1. #1
    Join Date
    Aug 2010
    Posts
    23

    Question Creating a toolbox type List

    Hi

    What I am aiming for is have a similar type of toolbox that is used by Visual C++ Express edition when creating forms etc .

    I would like to have a list of items which when one is selected I can drag it and paste it into the main screen (this is PLC program editor) . What type of form tool should one use ?

    Many Thanks
    Roy

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,594

    Re: Creating a toolbox type List

    My first bet would be a ListView control. It's items can have icons and tool tips, and it supports dragging items out of the control.

    What it, AFAIK, doesn't support are those collapsable categories that the toolbox in VC++ has.

    HTH to get you started at least.

  3. #3
    Join Date
    Aug 2010
    Posts
    23

    Re: Creating a toolbox type List

    Thanks

    I have added my items . Is there any way I can add an icon as well for each item.

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

    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  

  5. #5
    Join Date
    Aug 2010
    Posts
    23

    Re: Creating a toolbox type List

    Hi Thanks

    I have got it working . I also tried to bring the icons across as well and tried another listView - this didnt work.

    What my aim is to have a design sheet where the selected item is then dropped to the place as required in the schematic drawing .

  6. #6
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,594

    Re: Creating a toolbox type List

    Quote Originally Posted by rbettes View Post
    I also tried to bring the icons across as well and tried another listView - this didnt work.
    What are the problems you encounter? As you can see from the event handlers I posted above, you have access to the entire ListViewItem object in the drop target. The icon property is a simple integral index into the image list. If both controls refer to the same image list, or at least image lists that have matching icons set up at the respective indices, it should be no big deal. I didn't try that myself yet, though.

    Did you get the item tool tips working? I would be interested in how you did this.

    What my aim is to have a design sheet where the selected item is then dropped to the place as required in the schematic drawing .
    I'm not sure whether a list view is the right control for that purpose. At least you would have to derive a class from ListView and do some drawing yourself. But it might be better do implement the entire control more or less yourself, as that might provide a better fitting structure to map to the model you're working with.

  7. #7
    Join Date
    Aug 2010
    Posts
    23

    Re: Creating a toolbox type List

    Hi
    is there any chance of talking/ or online chatting about my project on Skype. My Skype name is roy_bettesworth .

    I am not sure which is the best way for me to proceed. I have an exsisting program which was written in win32 but does not use forms. I thought that using forms which has more upto date features might be easier and then link the two together. The exsisting program uses a window to do the schematics on .

    Thanks

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,594

    Re: Creating a toolbox type List

    Quote Originally Posted by rbettes View Post
    is there any chance of talking/ or online chatting about my project on Skype. My Skype name is roy_bettesworth .
    Sorry, I don't have a headset and thus have never seen any use for a Skype account.

    I am not sure which is the best way for me to proceed. I have an exsisting program which was written in win32 but does not use forms. I thought that using forms which has more upto date features might be easier and then link the two together. The exsisting program uses a window to do the schematics on .
    In that case, I think you can make use of the managed/native interop capabilities of C++/CLI, which are said to be the special strength of that language, and integrate and re-use some of the Win32 code you already have. But as I'm new to the entire world of .NET myself, I can't really tell you much about that by now, because I have not yet used these features. The least I can tell you is that you can, for example, obtain the "classic" Win32 HWND of the wrapped GDI object from any .NET object whose class is derived from Object by using its Handle property.

    I hope others can tell you more about that.

  9. #9
    Join Date
    Aug 2010
    Posts
    23

    Re: Creating a toolbox type List

    Can anyone help / give advice ?


    Thanks

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center