今天在使用ComboBoxEdit 这个控件的时候,不知道怎么添加值.
在官网上找到代码。在这里做个记录
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 = -; 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;
}
}
public class ExComboBox
{
public int Index { get; set; }
public string Key { get; set; }
public string Value { get; set; }
public string Tag { get; set; } public ExComboBox(int pIndex, string pKey, string pValue)
{
this.Index = pIndex;
this.Key = pKey;
this.Value = pValue;
} public ExComboBox(int pIndex, string pKey, string pValue, string pTag)
{
this.Index = pIndex;
this.Key = pKey;
this.Value = pValue;
this.Tag = pTag;
}
public override string ToString()
{
return this.Value;
}
}
comboBox.Properties.Items.Add("全部");
for (int i = ; i < arg.Result.Count; i++)
{
comboBox.Properties.Items.Add(new ExComboBox(i, arg.Result[i].F_RoadwayCode, arg.Result[i].F_StationCode.ToString()));
}
void comboBoxEditStation_SelectedValueChanged(object sender, System.EventArgs e)
{
var exComboBox1 = this.comboBoxEditRoadWay.SelectedItem as ExComboBox;
}