I'm having an issue with a ComboBoxEdit not sorting at times. Here is the situation... When the application starts, I populate the ComboBox items with an objects I created. The object has an override for the ToString method. These objects display the way i would expect when I look at the dropdown on the combobox. Now if I remove an item and later try to add it back in, the ComboBoxEdit doesn't sort, it appends the item to the end of the list. I would like the list to sort and for the item to appear in it's original place.
Here is the code:
public class ComboItem
{
private string m_value;
private string m_display;
public ComboItem (string value, string display)
{
m_value= value;
m_display= display;
}
public string Value
{
get { return m_value; }
}
public string Display
{
get { return m_display; }
}
public override string ToString()
{
return m_display;
}
}
The constructor for the Form containing the ComboBoxEdit contains this line:
m_categoriesComboBox.Properties.Sorted = true;
This is the code for removing an item:
ComboItem curItem = (ComboItem )m_categoriesComboBox.SelectedItem;
m_categoriesComboBox.Properties.Items.Remove(curItem);
// now insert object into grid
This is the code to add the item back into the combobox:
int handle = m_xtraGrid.FocusedRowHandle;
ComboItem newItem = new ComboItem(m_xtraGridView.GetRowCellValue(handle, CAT_ID), m_xtraGridView.GetRowCellValue(handle, CAT_DISPLAY));
m_categoriesComboBox.Properties.Item.Add(newItem);
At this point, the item being inserted is appended to the list. I would think, since the Sorted property is set to true that adding an item would put it in the proper location. I also tried the following with no success:
m_categoriesComboBox.Properties.BeginUpdate();
int handle = m_xtraGrid.FocusedRowHandle;
ComboItem newItem = new ComboItem(m_xtraGridView.GetRowCellValue(handle, CAT_ID), m_xtraGridView.GetRowCellValue(handle, CAT_DISPLAY));
m_categoriesComboBox.Properties.Item.Add(newItem);
m_categoriesComboBox.Properties.EndUpdate();
Any suggestions on how to do this?