我有一个方法(LoadCustomers()),它返回一个元素字典,如下所示:
Dictionary<int, string>()
我把它连接到这样的组合框的数据源:
Myclass m = new Myclass();
combo1.DataSource = new BindingSource(m.LoadCustomers(), null);
combo1.DisplayMember = "Value";
combo1.ValueMember = "Key";
现在我想在组合框的列表前放一个像:
这样的项目 <select one customer>
如何在winforms的c#中执行此操作?
很多
答案 0 :(得分:1)
将此选项添加到客户词典
const int EMPTYCUSTOMERKEY = -1; //be sure Customers will not contain this value
const string EMPTYCUSTOMERVALUE = "<select one customer>";
Myclass m = new Myclass();
Dictionary<int, string> customerSource = m.LoadCustomers();
customerSource.Add(EMPTYCUSTOMERKEY, EMPTYCUSTOMERVALUE);
combo1.DataSource = new BindingSource(customerSource, null);
combo1.DisplayMember = "Value";
combo1.ValueMember = "Key";