ListBox.ValueMember always returns "value"


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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?
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
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

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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.
Attachments
colorizedTextSample.zip (106 views, 780.00 KB)
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Thanks...that does reproduce the behavior you were explaining.  We will take a look at this. 
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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.

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
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.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Cool. I set RawText via code and it works! This is much more realistic usage in any case (or binding to data).
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Exactly...that is why we had not yet run into this Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search