这样的“List<>集合”应该怎样绑定
方法:
private static List<IDictionary<string, string>> DataTableToList(DataTable dt)
{
var list = new List<IDictionary<string, string>>();
foreach (DataRow row in dt.Rows)
{
list.Add(new Dictionary<string, string>
{
{"code_key",row.Field<string>("code_key").Trim()},
{"code_name",(row.Field<string>("code_name")??string.Empty).Trim().Replace("'","''")},
{"ref_val_1",(row.Field<string>("ref_val_1")??string.Empty).Trim().Replace("'","''")},
{"ref_val_2",(row.Field<string>("ref_val_2")??string.Empty).Trim().Replace("'","''")},
{"ref_val_3",(row.Field<string>("ref_val_3")??string.Empty).Trim().Replace("'","''")}
});
}
return list;
}
描述:
可以看出,方法是将“DataTable”结果集,转化为了“List<>集合”和“Dictionary<>集合”的组合,List<>就好比表,“Dictionary<>”就好比每一行的记录。
问题:这样的“结果集”该怎样作为数据源绑定呢?
比如“List<T>”可以这样的结果集,可以:
cb_chartType.ItemsSource = slcharttypes;
cb_chartType.SelectedValuePath = "Value";
cb_chartType.DisplayMemberPath = "Text";
cb_chartType.SelectedIndex = 0;
而现在“实体集对象”为“Dictionary”,它也是一个集合。要绑定的项也为一个“集合”,咋处理?
比如:现在想绑定“code_name”这一列,应该不能叫“列”了,应该叫“List集合”下每一项“Dictionary集合”的“code_name键”的值,应该怎么办???