in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

ComboBoxEdit Sorting Issue

Last post 10/4/2007 11:59 AM by bucman6. 3 replies.
Page 1 of 1 (4 items)
Sort Posts:
Previous Next
  • 10/3/2007 5:44 PM

    ComboBoxEdit Sorting Issue

    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?

    Filed under: ,
  • 10/4/2007 3:53 AM In reply to

    Re: ComboBoxEdit Sorting Issue

    Hello,

    bucman6:
    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();
    Try the following code instead:

    m_categoriesComboBox.Properties.Items.BeginUpdate();
    .
    .
    .
    m_categoriesComboBox.Properties.Items.EndUpdate();

    You might also read the following Support Center issue: http://www.devexpress.com/Support/Center/p/CS57305.aspx

    Hope this helps,
    Holger

    Holger Persch - [DX-Squad]
  • 10/4/2007 11:20 AM In reply to

    Re: ComboBoxEdit Sorting Issue

    Thank you for the suggestion, I appreciate it.  I implemented your suggestion and called the BeginUpdate and EndUpdate from the Item data member instead of the Property.  This had no effect on the sorting of the list in my application.  I also read the article you posted and it raised a question: If I want to add a single item to the ComboBox list after it has been used, do I have to clear the list and repopulate it so that it sorts?

     Thank you for the help...

  • 10/4/2007 11:59 AM In reply to

    Re: ComboBoxEdit Sorting Issue

    I also tried inserting the items in a different order and the dropdown in the combobox doesn't appear to be sorting at all.

Page 1 of 1 (4 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED