的输入我想要定义一个通用的方法来填充Windows窗体上的ComboBox控件。我通常使用Dictionary将他们绑定到数据源来填充我的组合框。由于我有一些这样的人,我想创建一个方法,我可以调用任何键,值对的组合。这里是我的尝试:使用未定义的字典<Type, Type>作为方法
private void PopulateDropdown(ComboBox control, Dictionary<Type, Type> dict)
{
if (dict.Count > 0)
{
control.DataSource = new BindingSource(dict, null);
control.DisplayMember = "Key";
control.ValueMember = "Value";
}
}
我想能够调用它像这样:
PopulateDropdown(cbPrinters, this.inputData.Printers);
其中this.inputData.Printers
是字典与键/值类型为字符串,字符串,但我也有其他组合一样串,int或者string,object。
我得到一个错误,无法将字符串,字符串转换为类型,类型。我怎样才能解决这个问题?
啊!这似乎运作良好。非常感谢澄清。 – konrad