Long time no post! I hope everyone's well!

I'd appreciate some input here on this one...

I still, even after reading the MSDN documentation on the Listbox and ListControls, have no clue what exactly these properties are for.

I'm assuming the SelectedValue property, when accessed, returns the "value" of the item in the list that is selected, like the listbox might show employee names, but the real "value" of the items is the employee number or something; I think I get that, but ValueMember?

I thought that the ValueMember was used if you bound data to the listbox, the ValueMember was the column (or whatever) that the SelectedValue got it's value from, but that doesn't seem to be true, considering in a databound listbox, you can select a column name for the SelectedValue property and it works, even if you leave the ValueMember set to "None"

Could someone explain what these two properties really are, in simplistic terms, but not too simplistic, the MSDN site achieves that already.

Recommended Answers

As far as I understand it.

The values set in the ValueMember is the value being returned after selecting something in the listbox. as you said, the If it displays employees, it doesnt mean the value is the employee names, more rather the employee IDs.

So when binding …

Jump to Post

All 3 Replies

As far as I understand it.

The values set in the ValueMember is the value being returned after selecting something in the listbox. as you said, the If it displays employees, it doesnt mean the value is the employee names, more rather the employee IDs.

So when binding the data, you can set the DataMember(what is seen) and the ValueMember(the value behind).

and you are correct about the SelectedValue. It just means that you want the value of the SelectedItem in the listbox

Correct me if I am wrong.

I still don't get it. Does that mean a item in the listbox can have 3 values? A displayed value, a selected value and a value member value?

the value you put in the ValueMember is the value you will get when using SelectedValue

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.