如何获取wpf工具包datagrid在绑定到数据集时显示新行 [英] how to get the wpf toolkit datagrid to show new rows when bound to dataset
问题描述
有没有办法获取wpf工具包 DataGrid
在绑定到 DataSet
时显示新行?换句话说,我有一个 DataGrid
,我已经将 ItemsSource
设置为 DataTable
,一切似乎都可以正常工作,除非我无法让网格显示我以程序方式添加到 DataTable
的行。
您可以将 datagrid.ItemsSource
设置为 ObservableCollection< T>
。
ObservableCollection< YourItem> items = new ObservableCollection< YourItem>();
yourDataGrid.ItemsSource = items;
然后,您应该能够添加到集合中以获取新行显示: p>
编辑:根据更新的信息。
if(Dispatcher.CheckAcces())
{
//已在线程UI控件上创建
items.Add(<您的项目>);
}
else
{
//在同一个线程上更新UI $控件是在
上创建的// BeginInvoke将调用一个委托,它将调用items.Add(<你的项目>)
Dispatcher.BeginInvoke(...);
}
请参阅 Dispatcher 。所有 System.Windows.UserControl 对象都有一个调度程序
属性。
Is there a way to get the wpf toolkit DataGrid
to show new rows when its bound to a DataSet
? In other words, I have a DataGrid
, I've set its ItemsSource
to a DataTable
, and everything seems to work fine, except I can't get the grid to show rows that I add to the DataTable
programatically.
You can set the datagrid.ItemsSource
to an ObservableCollection<T>
.
ObservableCollection<YourItem> items = new ObservableCollection<YourItem>();
yourDataGrid.ItemsSource = items;
Then you should be able to just add to the collection to get the new rows to appear:
Edit: Based on updated info.
if (Dispatcher.CheckAcces())
{
// already on thread UI control was created on
items.Add(<your item>);
}
else
{
// update on same thread UI control was created on
// BeginInvoke would invoke a delegate which would call items.Add(<your item>)
Dispatcher.BeginInvoke(...);
}
See Dispatcher. All System.Windows.UserControl objects have a Dispatcher
property.
这篇关于如何获取wpf工具包datagrid在绑定到数据集时显示新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!