Reputation: 469
I have a dictionary with several items in it:
public static Dictionary<string, string> vmDictionary = new Dictionary<string, string>();
And I have a method to add the items from within it to a listbox:
foreach (KeyValuePair<String, String> entry in MyApp.vmDictionary)
{
ListViewItem item = new ListViewItem();
item.SubItems.Add(entry.Value[0]);
item.SubItems.Add(entry.Value[1]);
selectVMListView.Items.Add(
}
Although I get the following error:
Error 2 Argument 1: cannot convert from 'char' to 'string'
Relating to these lines:
item.SubItems.Add(entry.Value[0]);
item.SubItems.Add(entry.Value[1]);
entry.Value[0] and [1] should be string if I am not mistaken, but for some reason its complaining they are chars :S
Upvotes: 0
Views: 414
Reputation: 12618
item.SubItems.Add(entry.Value[0]);
item.SubItems.Add(entry.Value[1]);
You are trying to add first char of Value in KeyValuePair. Maybe you are trying to do this?
item.SubItems.Add(entry.Key);
item.SubItems.Add(entry.Value);
Upvotes: 1
Reputation: 19416
entry.Value
returns the value component of the KeyValuePair<,>
, which in this case is a string
, when you then use an index on this string
, you are getting a char. I think what you mean to have is the following:
item.SubItems.Add(entry.Key);
item.SubItems.Add(entry.Value);
Upvotes: 1