问题描述
ComboBoxEdit
( DevExpress.XtraEditors
)有一个小问题。我无法为 ComboBoxExit
添加值或设置 SelectedIndex
。
ComboBoxEdit组合=新的ComboBoxEdit();
ComboBoxItemCollection coll = combo.Properties.Items;
coll.BeginUpdate();
试试
{
coll.Add(new PersonInfo( Sven, Petersen));
coll.Add(new PersonInfo( Cheryl, Saylor));
coll.Add(new PersonInfo( Dirk, Luchte));
}
最终
{
coll.EndUpdate();
}
combo.SelectedIndex = -1; Comboboxedit1.Properties.Items.Add(combo);
它不起作用,仅显示以下内容:
同一行:
Comboboxedit1.Properties.Items.Add(combo);
您要在其内部添加ComboBox对象。 ComboBoxEdit
ToString()方法返回您在屏幕快照中看到的名称。
因此,请删除此行。 / p>
您的代码取自官方(上面应删除的行除外),并且工作正常:确实已添加项目。
但是,设置 SelectedIndex
属性为-1不会选择任何内容,如文档所述:
您可以执行以下操作:
combo.SelectedIndex = 0; //选择Sven
或
combo.SelectedIndex = 1; //选择Cheryl
或
combo.SelectedIndex = 2; //选择Dirk
I have a small problem with ComboBoxEdit
(DevExpress.XtraEditors
). I cannot add a value or set SelectedIndex
for my ComboBoxExit
.
ComboBoxEdit combo = new ComboBoxEdit();
ComboBoxItemCollection coll = combo.Properties.Items;
coll.BeginUpdate();
try
{
coll.Add(new PersonInfo("Sven", "Petersen"));
coll.Add(new PersonInfo("Cheryl", "Saylor"));
coll.Add(new PersonInfo("Dirk", "Luchte"));
}
finally
{
coll.EndUpdate();
}
combo.SelectedIndex = -1; Comboboxedit1.Properties.Items.Add(combo);
It does not work and just adds shows this:
WIth this line :
Comboboxedit1.Properties.Items.Add(combo);
You are adding the ComboBox object inside itself. ComboBoxEdit
ToString() method returns the name you are seeing in your screenshot.
So, remove this line.
Your code in taken from the official DevExpress documentation (except the line above that you should remove), and works fine : items are indeed added.
However, setting the SelectedIndex
property to -1 doesn't select anything, as the documentation states :
You can do :
combo.SelectedIndex = 0; // Select Sven
Or
combo.SelectedIndex = 1; // Select Cheryl
Or
combo.SelectedIndex = 2; // Select Dirk
这篇关于如何将项目添加到ComboBoxEdit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!