M
Mike Hofer
I am trying to do something a little nonstandard, and am having some
difficulty determining (a) if it can be done and (b) if so, how to do it.
What I want to do is fill a dropdown combobox with data from a collection.
Then, I want to bind that list to a member of a custom class. (Don't ask
why, just trust me on that one. <gr>).
What I'm doing now is binding the combo box to a collection, as follows:
Dim items As ArmorTypeCollection = ArmorTypeDac.Select()
With Me.ArmorType
.DataSource = items
.DisplayMember = "Value"
.ValueMember = "ID"
End With
Then, when the data is loaded onto the form, I set the default member as
follows:
Dim item As ArmorType
For Each item In ArmorType.Items
If item.ID.ToString() = _armor.Type.ID.ToString() Then
ArmorType.SelectedItem = item
Exit For
End If
Next
When the user commits her changes, I load them back into the object as
follows:
_armor.Type = ArmorTypeDac.Select().Item(Me.ArmorType.SelectedValue())
Is there a better way to do this? Essentially, my _armor object (of type
Armor) has a reference to an item in the armor type collection.
Any help would be greatly appreciated.
difficulty determining (a) if it can be done and (b) if so, how to do it.
What I want to do is fill a dropdown combobox with data from a collection.
Then, I want to bind that list to a member of a custom class. (Don't ask
why, just trust me on that one. <gr>).
What I'm doing now is binding the combo box to a collection, as follows:
Dim items As ArmorTypeCollection = ArmorTypeDac.Select()
With Me.ArmorType
.DataSource = items
.DisplayMember = "Value"
.ValueMember = "ID"
End With
Then, when the data is loaded onto the form, I set the default member as
follows:
Dim item As ArmorType
For Each item In ArmorType.Items
If item.ID.ToString() = _armor.Type.ID.ToString() Then
ArmorType.SelectedItem = item
Exit For
End If
Next
When the user commits her changes, I load them back into the object as
follows:
_armor.Type = ArmorTypeDac.Select().Item(Me.ArmorType.SelectedValue())
Is there a better way to do this? Essentially, my _armor object (of type
Armor) has a reference to an item in the armor type collection.
Any help would be greatly appreciated.