Quantcast
Viewing all articles
Browse latest Browse all 27072

How to add items to listbox using class (winforms)

I've got a class called SelectListItems with 2 properties (Text/Value)
I need the user to be able to add multiple items (one at a time), so I have 2 textboxes with an 'add' button
I did this all the time with VB6, but I just can't seem to get the hang of this - -

I need the 'Text' property to be the DisplayMember and the 'Value property to be the ValueMember

I've tried all kinds of stuff like the following:
SelectListItem sl = new SelectListItem();
sl.Text=txtItem.Text;
sl.Value=txtValue.Text;
lstItems.Items.Add(new SelectListItem());
tried:
lstItems.DisplayMember = sl.Text;
lstItems.ValueMember = sl.Value;

What am I missing here? I know this must be so simple - I'm just missing it

Viewing all articles
Browse latest Browse all 27072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>