1

我正在用 type 的下拉值填充组合框WagonType。我正在调用的函数返回一个字典,其中键是WagonTypeID,值是WagonType

RepositoryItemComboBox comboWagonTypes;
Dictionary<int, WagonType> GetAllWagonTypes()
{
  ...
}

如果我使用 AddRange 填充集合,它将只插入值还是同时插入键和值?

comboWagonTypes.Items.AddRange(GetAllWagonTypes());

还是我需要遍历字典并自己插入值?

foreach (var wagonType in GetAllWagonTypes())
   comboWagonTypes.Items.Add(wagonType.Value)
4

2 回答 2

4

您需要使用字典的Values属性。

做就是了

comboWagonTypes.Items.AddRange(GetAllWagonTypes().Values);
于 2013-01-16T07:49:20.010 回答
0

只需使用Values属性。字典具有键和值作为属性。试试看!

于 2013-01-16T07:51:42.730 回答