将数据添加到WPF的DataGrid [英] Adding data to WPF DataGrid
本文介绍了将数据添加到WPF的DataGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想加我的DataGrid中的一些数据。
I am trying to add some data inside my DataGrid.
我添加了一些列与设计师。现在我想与DataGrid中添加数据行。
I added some columns with the designer. Now I want to add rows with data inside the DataGrid.
下面是我的code到目前为止:
Here's my code so far:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var dataContext = new PurchaseOrderDataContext();
var purchaseOrderTable = dataContext.GetTable<PurchaseOrder>();
var query = from a in purchaseOrderTable
select a;
var purchaseOrders = query;
foreach (var purchaseOrder in purchaseOrders)
{
// I believe that this method is the right one, but what do I pass to it?
// dataGrid1.Items.Add(test);
}
}
所有我想知道的是:什么样的对象,我需要用它来添加一些在DataGrid中,和我需要传递给最后的方法是什么样的对象?另外我怎么添加,比方说,文本行我加?的某列
All I want to know is: What kind of object do I need to use to add something in the DataGrid, and what kind of object do I need to pass to that last method? Also how do I add, let's say, text to a certain column of a row I added?
非常感谢!
推荐答案
试试这个:
dataGrid1.ItemsSource = query;
这篇关于将数据添加到WPF的DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文