我正在创建一个DataGrid,该字段由包含字符串作为键和List作为值的字典中的值填充。关键应该是列的标题和列表的内容是该列的内容:从上到下填充DataGrid
header1(key) header2(key) header3(key)
value1fromList value1fromList value1fromList
value2fromList value2fromList value2fromList
value3fromList value3fromList
对于这一点,我创建一个充满这个值和作为的ItemSource为一个DataTable数据网格。我的问题是我不知道如何以这种方式填充DataTable。我的解决方案只是填充DataTable一些空白并覆盖现有的值。
http://oi64.tinypic.com/20f45eh.jpg
public void FillDataGrid(Dictionary<string, List<string>> valuedict)
{
myGrid.Columns.Clear();
var dt = new DataTable();
DataRow row = null;
foreach(KeyValuePair<string, List<string>> entry in valuedict)
{
dt.Columns.Add(entry.Key);
foreach (string word in entry.Value)
{
row = dt.NewRow();
row[entry.Key] = word;
}
dt.Rows.Add(row);
}
myGrid.ItemsSource = dt.AsDataView();
}
你能给我们一个你的代码产生的例子吗?你已经向我们展示了你想要的东西。你目前得到什么? –
添加了截图 – Scorch