Tuesday, June 7, 2011

ListBox Control DisplayMember Property Issue

My goal was to add a ListBox Control and add Class Objects Items to it. The Display Values should be one of the class member variables.

I have declared a string variable  (m_Name) which is public (It's basically a "Field" of the class) and then I also assigned the ListBoxControl.DisplayMember = "m_Name" ;

This was not working and the ListBox Control was always showing the Class.ToString() value and not my expected class member value.

After few Googling,  I found out that it should be a "Property" of the class not the "Field".

Once I created a "Property" and assigned it to the ListBoxControl.DisplayMember then it started to display the correct value.

Hope this saves some time.

Happy Coding !

All Blogs so far ...