ComboBox Sorting Defect!

less than 1 minute read

Oops! Never expected this behavior from such a standard control: Winforms ComboBox.

One of the common things our applications require is bind a data source with Collection-base UI elements like ComboBox. The best code any one could write would be: 

cmbTest.DisplayMember = "Name";
cmbTest.ValueMember = "ID";
cmbTest.DataSource = _employeeRecords; 

I would give this a perfect 10!

The combo box displays all the Employee Names in the combo box.  What if you wanted to sort these items?

Let's use the Sorted property of ComboBox.

this.cmbTest.Sorted = true;

Dush!!!  The code stopped working.

You won't see Employee Names in the combo box any more. What you would come through is items showing the namespace of the object


Now did you expect that?