Current filter:
                                You should refresh the page.
                                0
                                  • ComboBoxEdit.set_SelectedItem behaves like this:

                                        if (Properties.Items.Contains(value)) EditValue = value;

                                    This code malfunctions if the object.Equals() operator has been overloaded, because it's technically assigning an EditValue that's not actually in the Properties.Items list. The correct implementation would be like this:

                                        int index = Properties.Items.IndexOf(value);
                                        if (index != -1) SelectedIndex = index;

                                    This code guarantees that the selected item will actually be in the list, rather than merely being equivalent to an item in the list.

                                    The functions BaseListBoxControl.OnSetItem() and ListBoxControl.SetItemCore() implement the algorithm correctly, which is more evidence that the ComboBoxEdit is incorrect.

                                    This bug prevented me from using an item wrapper class as a workaround for another ComboBoxEdit bug (B141380). Please fix the combo box!

                                0

                                Hello,

                                Further investigation has not proved the problem. Here is the implementation of the ComboBoxItemCollection.Contains method:

                                	
                                [C#]
                                public virtual bool Contains(object item) { return IndexOf(item) != -1; }

                                So, there is no problem here.

                                Below is our code for the ComboBoxEdit.SelectedIndex property:

                                	
                                [C#]
                                public virtual int SelectedIndex { get { return Properties.Items.IndexOf(SelectedItem); } set { if(value < 0 || value >= Properties.Items.Count) SelectedItem = null; else SelectedItem = Properties.Items[value]; } }

                                Both members are virtual and therefore can be overridden in descendants, if you still want to change their behavior.

                                Thanks,
                                Nick
                                --------------------
                                Check if Search Engine is able to answer questions faster than I do!

                                0

                                I think you misunderstood what I wrote. It was a complicated explanation, but maybe object identity is an inherently complicated topic. :-)

                                You pasted source code for Contains() and SelectedIndex, but the problem I reported is in the ComboBoxEdit.SelectedItem property.

                                Suppose we have a class like this:

                                  class CExampleItem {
                                    public string Filename;

                                    [...]

                                    public override string ToString() {
                                      return Filename;
                                    }

                                    // CExampleItem instances are considered equivalent if their filenames are the same
                                    public override bool Equals(object obj) {
                                      return Filename == ((CExampleItem)obj).Filename;
                                    }
                                  }

                                Now suppose several CExampleItem instances have been added to the ComboBoxEdit.Properties.Items list, and then this happens:

                                  CExampleItem notInList = new CExampleItem();
                                  notInList.Filename = "Example.dat";
                                  
                                  MyComboBoxEdit.SelectedItem = notInList;

                                Let's suppose there's a different CExampleItem in the list whose filename is also "Example.dat". Contains() will compare them using Equals() and return true, but the resulting EditValue is the notInList value:

                                    if (Properties.Items.Contains(value)) EditValue = value;

                                By contrast, your ListBoxControl uses this approach, which will correctly set EditValue to the matching item in the list:

                                    int index = Properties.Items.IndexOf(value);
                                    if (index != -1) SelectedIndex = index;

                                0

                                Hello,

                                > if (Properties.Items.Contains(value)) EditValue = value;
                                I cannot find the above code line in our ComboBoxEdit class. Could you please describe your requirements in greater detail?

                                Thanks,
                                Nick
                                --------------------
                                Check if Search Engine is able to answer questions faster than I do!

                                0

                                Hi Nick,

                                This is the DLL:

                                DevExpress.XtraEditors.v9.2, Version=9.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a

                                This is the class:

                                DevExpress.XtraEditors.ComboBoxEdit

                                This is the method:

                                public virtual object SelectedItem {
                                  get { }
                                  set { ... } <----- this one
                                }

                                Let me know if you need anything else. Thanks!

                                0

                                Pete,

                                Sorry for misunderstanding. I see the problem. Your issue report has been reassigned to the R&D team.

                                Thanks,
                                Nick

                                You must  log in  or  register  to leave an answer

                                Is your intention to post an answer to your own question?

                                • If so, then proceed.
                                • If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
                                • If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.