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!
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;
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!
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!
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.
Facebook
Twitter
Google+