MySqlCommand cmd = new MySqlCommand(query, conn);
dt.Load(cmd.ExecuteReader());
List<string> list = new List<string>();
while (combodata.Read())
{
list.Add(combodata.GetString(0));
}
source.DataSource = dt;
dataGrid1.ItemsSource = source;
如何将list
添加到source
?
source.DataSource = dt;
source.DataSource = list;
...误
我需要添加dataGrid1.ItemsSource
dt
和list
我怎么样?
答案 0 :(得分:1)
您可以使用CompositeCollection
:
var cc = new CompositeCollection();
cc.Add(new CollectionContainer { Collection = new DataView(dt) });
cc.Add(new CollectionContainer { Collection = list });
dataGrid1.ItemsSource = cc;
答案 1 :(得分:0)
您无法将DataTable
设置为ItemsSource
,因为它未实现IEnumerable
。您可以使用DataView:
dataGrid1.ItemsSource = dt.AsDataView();