Had a very strange one the other day ... the conclusion is the Sorted property of the forms.combobox control should never be true when the combo box is using a datasource.
The combo box was set up no different - Set the DataSource with a DataRow[], Set the DisplayMember and ValueMember. The DataRow[] was already in the desired Description ASC sort order;
ID | Description |
302 | Alopecia |
345 | Appetite Decreased |
346 | Appetite Increased |
303 | Behavioural Abnormality |
304 | Bleeding |
313 | Dystocia |
So with the DisplayMember = Description column, the ValueMember = ID column and the Sorted property set to false.
As expected the SelectedValue returns the expected ID value.
However, with the DisplayMember = Description column, the ValueMember = ID column and the Sorted property set to true. The combo box data actually is;
ID | Description |
302 | Alopecia |
303 | Appetite Decreased |
304 | Appetite Increased |
305 | Behavioural Abnormality |
306 | Bleeding |
307 | Dystocia |
So the ValueMember has begun from the first ID value and just incremented as each item was bound.
In this case the use of SelectedItem.ID returns the correct ID value.
So just my experience ... maybe obvious ... but i have not seen this documented anywhere and surely i cant be the first person to have experienced it ?!?!?!!?
No comments:
Post a Comment