Why is this weirdness needed?


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Goodness, that must have been a fun one to track down! Thanks for the info!
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The problem generally occurs when there is an event handler on the combo's SelectedIndexChanged or SelectedValueChanged or other event that fires when the data source on the combo changes (or even if the combo is data-bound and the formatting can throw an exception).  If an exception is thrown from within the handler, .NET snuffs the exception (it doesn't ever bubble up) and the ComboBoxItemCollection is never properly populated with the display and value member values.  The value member is left as the raw collection object (the DataRowView), not the value of the property on the object.  The display member is then set to the ToString() of the raw object, so the combo box is then populated with several "{System.Data.DataRowView}" entries.  We added the code to attempt to circumvent the formatting errors that can occur when you set the data source.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I pulled this code form the code that loads a combo/list from an enum (I think). There is mention of some .NET weirdness that requires this. I'm wondering if you could shed a bit of light on why this is done? (Setting the display member and value member to ZLS, then to their actual values, then setting datasource, then setting them again!)





Private Sub SetDataSource(ByVal combo As SF.ComboBox _

, ByVal DataSource As Object _

, ByVal DisplayMember As String _

, ByVal ValueMember As String)

combo.BeginUpdate()

combo.DataSource = Nothing

combo.DisplayMember = String.Empty

combo.ValueMember = String.Empty

combo.DisplayMember = DisplayMember

combo.ValueMember = ValueMember

combo.DataSource = DataSource

combo.DisplayMember = DisplayMember

combo.ValueMember = ValueMember

combo.EndUpdate()

End Sub


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