StrataFrame Forum

ListBox.ValueMember always returns "value"

http://forum.strataframe.net/Topic3937.aspx

By Greg McGuffey - 10/27/2006

I'm trying to use your ListBox control (winform) and when I access the ValueMember property, the value is always "value". I have it setup to CopyDataFrom() and have set the ValueMember in the PopulationDataSourceSettings. It is hitting a business object that is correctly populated. How do I get the current value for the selected item within the list?
By Trent L. Taylor - 10/27/2006

If you are using the PopulationDataSourceSettings, the ValueMember defined in those settings is stored in the Tag property of the selected list item:

loValue = MyListView.SelectedItems(0).Tag

By Greg McGuffey - 10/30/2006

Here is the sample project. In doing this, I decided to take a screen print. You can see the VS 2005 in background, with correct rendering and in for ground, the runtime version (first firstScreenPrint.bmp). Right after I hit print screen though, the rendering was fixed (secondScreenPrint.bmp). Minimizing and restoring the runtime didn't fix it though.
By Trent L. Taylor - 10/30/2006

Thanks...that does reproduce the behavior you were explaining.  We will take a look at this. 
By Greg McGuffey - 10/30/2006

Oops. Sorry. Posted this reply to wrong topic!



However, on the original topic, the ValueMember sets the column that the SelectedValue property returns at runtime (not the Tag property). It's right there in the help file! DOH! Anyway it is working fine now.
By Trent L. Taylor - 10/30/2006

After looking at your sample a little closer, there is a workaround which will save us both some time.  If you take the exact same test and have it bound to data, it works.  Also, if you set the RawText property through code, it works.  The only time there is an issue is when the Text property is set within the designer.  So, to work around the problem, just set the RawText property in code or bind the control to a business object field and this will resolve the behavior you're encountering.
By Greg McGuffey - 10/30/2006

Cool. I set RawText via code and it works! This is much more realistic usage in any case (or binding to data).
By Trent L. Taylor - 10/30/2006

Exactly...that is why we had not yet run into this Smile