简体   繁体   English

如何在WPF应用程序中将数据加载到datagrid中

[英]How load data in datagrid in WPF Application

In WinForms i do this: 在WinForms中,我这样做:

var fromtable = from a in Table1 select a;
DataGridView.DataSource = fromtable;

And i see data. 而且我看到数据。 How make same in wpf application? 如何在WPF应用程序相同?

If i do like this: 如果我这样做:

Museum_TrueEntities me = new Museum_TrueEntities();
 var test = from a in me.Authors select a;
 dataGrid1.ItemsSource = test;

In result DataGrid is empty. 结果DataGrid为空。

对于数据表,我们这样做

mydatagrid.ItemSource = mydatatable.DefaultView

dont forget to set AutogenerateColumns=true in your datagrid. 不要忘记在数据网格中设置AutogenerateColumns = true。

if you create the columns by your self post some xaml and set the correct binding. 如果您通过自己创建列,则发布一些xaml并设置正确的绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM