|
-
Jun 21st, 2007, 07:49 AM
#1
Thread Starter
Hyperactive Member
[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)
-
Jun 21st, 2007, 08:34 AM
#2
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.
-
Jun 21st, 2007, 08:58 AM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|