我想在一個DataGrid
這樣顯示DataRows
的List
:顯示的DataRows列表DataGrid中
List<DataRow> grid = new List<DataRow>();
for (int i = 0; i <= dt.Rows.Count; i++)
{
grid.Add(dt.Rows[i]);
}
dataGrid1.ItemsSource = grid;
dt
是從哪裏獲得我的數據的DataTable
。 問題是,當我運行代碼datagrid
是空的。
這並不能工作:
datagrid1.DataContext = grid;
編輯: (XAML)
<DataGrid Name="dataGrid1" />
能否請您分享的XAML'datagrid1' –
如果添加'的ItemsSource =「{結合}」'在你的XAML –