Results 1 to 5 of 5

Thread: How can I add a button to a listbox (in another column)?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    20

    Post How can I add a button to a listbox (in another column)?

    Hi there!

    How can I add a button to a listbox? I mean: for every single item, one button. I want the button in another column.

    Cheerz.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: How can I add a button to a listbox (in another column)?

    I'm pretty sure you can't do that with a listbox. You can probably do that with a datagridview, and you could make that dgv look something like a listbox. Alternatively, you could create your own control, or just make something that looked and acted like a listbox but had buttons. The problem could be hooking up the button click event handlers to the buttons, though that is solvable, depending on which route you take.
    My usual boring signature: Nothing

  3. #3
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    307

    Re: How can I add a button to a listbox (in another column)?

    This is in the code bank by user NickThissen, is this what you're trying to do?

    http://www.vbforums.com/showthread.php?t=599375

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2011
    Posts
    20

    Re: How can I add a button to a listbox (in another column)?

    Works the datagridview the same as a listbox? (E.g: listbox1.items.add (MyItem)?

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: How can I add a button to a listbox (in another column)?

    No, the datagridview is a much different animal. It was really intended to display tabular data, such as datatables and dataviews, though you can use it to show any other kind of tabular data. I have never used it to hold controls, but have seen others do things like that.

    Keep in mind that a listbox is a pretty simple animal. You could create something that looked very much like a listbox by putting a panel on the form with a vertical scroll bar on one side and a series of labels running from top to bottom. Keep all the items in a list and fill the labels from those items whenever the scrollbar moves and you have a listbox. It wouldn't be as convenient as the single package Listbox control, but if you do it right, the end user will never know the difference.

    I am currently working on a project that has a horizontal list that works as I just described, except that, instead of strings in the list, there are pictures, and each picture has a radio button below it. It looks like you have a bunch of them and can scroll left and right through the images. In reality, there are four pictureboxes and four radio buttons, and the text of the radio button along with the image in the picturebox are set whenever the scrollbar is moved. You could do the same thing using strings and buttons on a panel. It may be easier than any other solution. Package it all into one class and you will have created a custom control.
    My usual boring signature: Nothing

Tags for this Thread

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