我想在我的WPF DataGrid中顯示的數據表的內容如何將數據表加載到WPF數據網格
在下面的帖子:
Why can't I bind the WPFToolkit DataGrid ItemSource to DataTable?
我找到的代碼:
myDataGrid.ItemsSource = myDataTable.DefaultView;
行爲很奇怪:它顯示n個空行,其中n是正確的:查詢結果n行!
那麼,爲什麼我看不到他們呢?
我想在我的WPF DataGrid中顯示的數據表的內容如何將數據表加載到WPF數據網格
在下面的帖子:
Why can't I bind the WPFToolkit DataGrid ItemSource to DataTable?
我找到的代碼:
myDataGrid.ItemsSource = myDataTable.DefaultView;
行爲很奇怪:它顯示n個空行,其中n是正確的:查詢結果n行!
那麼,爲什麼我看不到他們呢?
在沒有看到代碼,我猜你沒有AutoGenerateColumns
設置爲真。這很好,但如果您不是自動生成列,則需要手動將列定義添加到數據網格。
一種可能的解決方案是將DataGrid
替換爲DataGridView
,並將DataGridView.DataSource
屬性綁定到DataTable
本身。按this example:
dataGrid1.DataSource = table;
我們在談論WPF。 DataGridView是一個WinForms控件。 – TecMan 2016-09-28 07:44:33
DataGrid是否自動生成列? – 2010-11-09 13:48:30
+1是的我已經找到它... myGrid.AutoGenerateColumns = true;確實是這個問題。 – Asaf 2010-11-09 15:57:18