Windows List boxes

  • Thread starter Thread starter Sandy Murdock
  • Start date Start date
S

Sandy Murdock

I am used to asp.net where dropdown listboxes etc. contain 'items' which I
can easily loop through.

I am trying to figure out how Windows form list boxes (etc.) work.

For example: Can I (like in the web) have a listbox which displays the value
'John Smith' but when I get the selected value returns '1285' ?
(representing the id for John Smith)

Also I have a dropdownlist box from which the user can select multiple
items, how do I access those items?

Currently I have:

If lbRuleSet.SelectedItems.Count > 0 Then

and this works. It can tell if there is more than 0 items selected. How can
I loop through them and get the values? I found some code on the net but it
didn't work.
 
The simplest way to do this is store a class as
the object added to the listbox.

When you get the .SelectedItem, you cast it to your
class. This gives you all sorts of capabilities.

Myclass rob = (Myclass)lst.SelectedItem;

Take a look at the UIListBoxEditor class in the
sample below my signature for using a ListBox in a .NET PropertyGrid
control.
 
Thanks.

Your code is C# so it will take me a bit to figure it out, but I should be
okay. (I've done a small amount of Java before and the syntax is very
similar)

Thanks.

I THINK you have given me what I need.



Robbe Morris - [MVP] C# said:
The simplest way to do this is store a class as
the object added to the listbox.

When you get the .SelectedItem, you cast it to your
class. This gives you all sorts of capabilities.

Myclass rob = (Myclass)lst.SelectedItem;

Take a look at the UIListBoxEditor class in the
sample below my signature for using a ListBox in a .NET PropertyGrid
control.

--
Robbe Morris [Microsoft MVP - Visual C#]
.NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorial...af-5cd3abe27a75/net-propertygrid-control.aspx




Sandy Murdock said:
I am used to asp.net where dropdown listboxes etc. contain 'items' which I
can easily loop through.

I am trying to figure out how Windows form list boxes (etc.) work.

For example: Can I (like in the web) have a listbox which displays the
value 'John Smith' but when I get the selected value returns '1285' ?
(representing the id for John Smith)

Also I have a dropdownlist box from which the user can select multiple
items, how do I access those items?

Currently I have:

If lbRuleSet.SelectedItems.Count > 0 Then

and this works. It can tell if there is more than 0 items selected. How
can I loop through them and get the values? I found some code on the net
but it didn't work.
 
Back
Top