Results 1 to 3 of 3

Thread: [2005] Checked List Box

  1. #1

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    [2005] Checked List Box

    We are trying to add a checked list box into our form that has the display values and also has a hidden value related to each item in the checked list box.

    From what I understand is VB6 had this feature already built in where it had the List items, and then also the Item Data which corresponded to each item.

    Any suggestions on an alternative to this ?
    (trying not to use an array or array list)

  2. #2
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    Re: [2005] Checked List Box

    The content items of a Listbox in .NET are objects, so you can include your display and value items in an object. This gives you a lot more flexibility than what you had in VB6 but you'll need to think beyond just strings.

    Also, arrays and listboxes are much easier to deal with than they were in VB6. Take a look at the AddRange method.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Checked List Box

    If you were using s ListBox you assign a list of objects to the DataSource and then set a DisplayMember and ValueMember. The DisplayMember is the name of the property whose values get displayed and the ValueMember is the name of the hidden property you speak of. The corresponding value of the current selection would be retrieved from the SelectedValue property.

    The CheckedListBox doesn't support data-binding so that's not possible. You do as bgmacaw suggests and define a class or structure with a property corresponding to your hidden value. You'd then override the ToString method to return the values you want displayed in the control. You can then add items of that type to the CheckedListBox and the return value of each item's ToString method will be displayed and you can get the hidden value from the property you declared.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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