且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从wpf中的datagrid获取数据

更新时间:2023-10-03 21:47:22

获取所有数据"是什么意思?

数据网格中的数据可能会有一个潜在的源集合,可用于获取数据.
What do you mean by "get all the data"?

Data in the datagrid will probably have an underlying source collection which can be used to obtain data.


此处存在一种固有的误解,即应如何在数据网格中填充数据.您将要做的是在层次结构中的某个位置创建一个DataContext,网格将使用它作为绑定源. DataContext背后的数据可能会存储在ObservableCollection中,以便在从集合中添加/删除项目时更新网格(如果没有,则将在某个地方的IEnumerable列表中).使用此列表获取数据.
There is an inherent misunderstanding here of how the data should be populated in a datagrid. What you will have done is create a DataContext somewhere in the hierarchy which your grid will use as the source for its binding. The data behind the DataContext will probably be stored in an ObservableCollection so that the grid gets updated as items are added/removed from the collection (if not, it will be in an IEnumerable list somewhere). Use this list to get your data.