如何将数据表加载到wpf数据网格中

时间:2010-11-09 13:45:37

标签: wpf datagrid

我正在尝试在我的wpf datagrid中显示数据表的内容

在以下帖子中:

Why can't I bind the WPFToolkit DataGrid ItemSource to DataTable?

我找到了代码:

myDataGrid.ItemsSource = myDataTable.DefaultView;

并且行为很奇怪:它显示n个空行,其中n是正确的:查询结果n行!

那为什么我不能看到它们呢?

2 个答案:

答案 0 :(得分:2)

如果没有看到代码,我猜你没有将AutoGenerateColumns设置为true。这没关系,但如果您不自动生成列,则需要手动将列定义添加到数据网格中。

答案 1 :(得分:-2)

一种可能的解决方案是将DataGrid替换为DataGridView,并将DataGridView.DataSource属性绑定到DataTable本身。根据{{​​3}}:

dataGrid1.DataSource = table;

相关问题