DevExpress的ComboBoxEdit控件:
我在控件中按照以下方法添加数据:
public class Class1
{
public int a{get;set;}
public string b{get;set;}
public override string ToString()
{ return this.b; }
}private void InitComboBox()
{
Class1 c1 = new Class1();
this.ComboBoxEdit1.Properties.Items.Add(c1);
Class1 c2 = new Class1();
this.ComboBoxEdit1.Properties.Items.Add(c2);
}在窗口Load事件中完成InitComboBox函数后,如果我要给定一个值,能不能用this.ComboBoxEdit1.EditValue="1";
如果没有变更值,那么
Class1 c3 = this.ComboBoxEdit1.EditValue as Class1;
c3的值为空。
请问我要如何在Load中给定一个值,在不变更的时候才能获取到有效的值?
我在控件中按照以下方法添加数据:
public class Class1
{
public int a{get;set;}
public string b{get;set;}
public override string ToString()
{ return this.b; }
}private void InitComboBox()
{
Class1 c1 = new Class1();
this.ComboBoxEdit1.Properties.Items.Add(c1);
Class1 c2 = new Class1();
this.ComboBoxEdit1.Properties.Items.Add(c2);
}在窗口Load事件中完成InitComboBox函数后,如果我要给定一个值,能不能用this.ComboBoxEdit1.EditValue="1";
如果没有变更值,那么
Class1 c3 = this.ComboBoxEdit1.EditValue as Class1;
c3的值为空。
请问我要如何在Load中给定一个值,在不变更的时候才能获取到有效的值?
不过道理应该是一样的
this.ComboBoxEdit1.Properties.Items应该是一个Objectcollection
他应该可以用索引来找到一个具体的ITEM吧Class1 c3 = this.ComboBoxEdit1.Properties.Items[0] as Class1;
-------------------------
int SelectedIndex =0;
void Form_Load()
{
SelectedIndex =5;
}void AnotherVoid()
{
Class1 c3 = this.ComboBoxEdit1.Properties.Items[SelectedIndex ] as Class1;
}
ComboBoxEdit用得不多,我一般都是用LookUpEditComboBoxEdit 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;
Controls.Add(combo);
//... public class PersonInfo {
private string _firstName;
private string _lastName;
public PersonInfo(string firstName, string lastName) {
_firstName = firstName;
_lastName = lastName;
} public override string ToString() {
return _firstName + " " + _lastName;
}
}