M
mcollier
I'm having some trouble getting databinding to a ListBox to work
correctly. I think the collection I'm trying to bind against is a
little odd, so I'm wondering if that could be part of the problem.
Below is a sample of the databinding code.
AxisCollection axis = GetAxisCollection()
myListBox.DataSource = null;
myListBox.Items.Clear();
myListBox.DisplayMember = "Attribute.Name";
myListBox.ValueMember = "Attribute.AttributeID";
myListBox.DataSource = attribs;
AxisCollection is a collection which derives from List<Axis>.
The Axis class looks something like:
Attributes
Name
AttributeID
DisplayNumber
Attributes is a reference type property for the Axis class.
After setting the DataSource property, I notice (using the debugger)
that the DisplayMember property changes to an empty string.
When I look at the displayed values in the listbox, they are just the
name of the class (repeated for each element in the collection).
Interestingly, if I change the myListBox.DisplayName to a value type
(i.e. "DisplayNumber") on the class, the value is displayed correctly
in the ListBox and the DisplayName remains after setting the
DataSource.
Any ideas on what could be going on would be greatly appreciated.
Thanks!
correctly. I think the collection I'm trying to bind against is a
little odd, so I'm wondering if that could be part of the problem.
Below is a sample of the databinding code.
AxisCollection axis = GetAxisCollection()
myListBox.DataSource = null;
myListBox.Items.Clear();
myListBox.DisplayMember = "Attribute.Name";
myListBox.ValueMember = "Attribute.AttributeID";
myListBox.DataSource = attribs;
AxisCollection is a collection which derives from List<Axis>.
The Axis class looks something like:
Attributes
Name
AttributeID
DisplayNumber
Attributes is a reference type property for the Axis class.
After setting the DataSource property, I notice (using the debugger)
that the DisplayMember property changes to an empty string.
When I look at the displayed values in the listbox, they are just the
name of the class (repeated for each element in the collection).
Interestingly, if I change the myListBox.DisplayName to a value type
(i.e. "DisplayNumber") on the class, the value is displayed correctly
in the ListBox and the DisplayName remains after setting the
DataSource.
Any ideas on what could be going on would be greatly appreciated.
Thanks!