Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi!

Can somebody please explain to me what the ValueMember property of the ListBox class does?

Thanks in advance!
Posted
Updated 17-Jan-11 12:46pm
v3

1 solution

A ListBox has display strings those are the ones you see in the GUI and associated with each of these display strings is a value. So the DisplayMember of ListControl gives you the string as you see it in your GUI and the ValueMember property of ListControl (ListBox is derived from ListControl) gives you the associated value.

Please see the example on this site: http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.valuemember.aspx[^]
The example is on the ListControl class site, but it contains an example using the ListBox class.

Hope that helps you!

Best regards,
Manfred
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 17-Jan-11 19:16pm    
Good answer (my 5), but Microsoft explanation seems to be more clear than yours.
It should be noted, this thing is invented to provide some binding flexibility based on Reflection.

In my opinion, this is yet another example of Microsoft's technological abuse usual in WinForm library: you see, the ValueMember is of type string, but supposed to be one of member names. If anyone create a string constant for this purpose and misprints it, the compiler is unable to issue a warning and this problem.
Manfred Rudolf Bihy 17-Jan-11 19:20pm    
I totally agree with you, if they would have had anything useful in mind they should have made the value part of type object, but hey I'm no Microsoft engineer so what do I know! :)
Sergey Alexandrovich Kryukov 17-Jan-11 19:23pm    
I know. All we can do it to prefer one ways of doing thing and be careful with others -- sometimes it helps to save some part of developer's life.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900