Reputation: 1309
I am filling a combobox with dropdown values of type WagonType
. The function I am calling returns a dictionary where the key is the WagonTypeID
and the value is the WagonType
.
RepositoryItemComboBox comboWagonTypes;
Dictionary<int, WagonType> GetAllWagonTypes()
{
...
}
If I use AddRange to fill the collection will it insert only the values or both the keys and the values?
comboWagonTypes.Items.AddRange(GetAllWagonTypes());
Or do I need to iterate through the dictionary and insert the values myself?
foreach (var wagonType in GetAllWagonTypes())
comboWagonTypes.Items.Add(wagonType.Value)
Upvotes: 1
Views: 158
Reputation: 11357
Just use the Values property. Dictionary has Keys and Values as properties. Give it a try!
Upvotes: 0
Reputation: 7212
You need to use the Values property of the dictionary.
Just do
comboWagonTypes.Items.AddRange(GetAllWagonTypes().Values);
Upvotes: 4