I have a data dictionary which is as follows:
Key Value
1 ron k polito
2 Ryan s Winslate
I am trying to display the Value column in a datagridview with three different columns firstname, midname and lastname. The below statement names.getnames().ToList() retrieves the names (value) from the data dictionary.
datagridview1.DataSource = names.getnames().ToList();
By moving the list into datagridview creates exactly same number of rows as total number of count retrieved by the data dictionary, but it doesnot display the anything. just the blank rows appear.
I am new to C#, any suggestion how can I fix this.
Thanks.
Here’s the code:
List<localname> lname_list = new List<localname>();
var l_names = names.getnames().ToList();
foreach(var lcname in l_names)
{
string[] wrd = lcname.Split(' ');
localname lv = new localname();
lv.mylocal(wrd[0], wrd[1], wrd[2]);
lname_list.Add(lv);
}
datagridview1.DataSource = lname_list;
ShowDialog();
With LINQ you can do this with few lines of code.
Provided you have a Custom class like
and your dictionary value has the first. mid, last names (meaning the value should always have 3 parts); you can do this.
Ouput