如何实例化Datagridview(在代码后面) [英] How to instantiate a Datagridview(in code behind)
问题描述
现在我正在进行如下
grid = new Microsoft.Windows.Controls.DataGrid();
我的数据表作为
table = new System.Data.DataTable();
,我通过执行
$ b $填写datagrid b
grid.ItemsSource = table.DefaultView;
然而,由于我遇到困难,我要删除datagrid的列等,我想转到Datagridview而不是datagrid。
我试过
grid = new Microsoft.Windows.Controls.DataGridview(); // WRONG
但显然不正确的方式。
我该怎么做?
注意:
框架3.5 / WPF。
你想在WPF中使用本地Winforms DataGridView吗?如果是,您应该使用WindowFormsHost并在其中放置DataGriView。
BTW,在从绑定表中删除列后,是否尝试重新绑定datagrid?我非常确定重新绑定或重新设置'ItemsSource'应该可以工作。
I am actually using a datagrid which is filled by a datatable to display my data(NOTE: These are dynamic data). Till now I was proceeding as below
grid = new Microsoft.Windows.Controls.DataGrid();
My datatable as
table = new System.Data.DataTable();
and I fill the datagrid with the datatable by doing
grid.ItemsSource = table.DefaultView;
However Due to dificulties I am facing to delete a column etc of the datagrid,I want to move to Datagridview instead of the datagrid.
I tried
grid = new Microsoft.Windows.Controls.DataGridview(); //WRONG
But it is aparently not the correct way.
How do I do this?
NOTE: Framework 3.5 / WPF.
Do you want to use native Winforms DataGridView in WPF? If yes, you should use WindowFormsHost and place DataGriView inside it. BTW, did you tried rebinding the datagrid after removing the column from your bound table? I am very sure that rebinding or restting the 'ItemsSource' should work.
这篇关于如何实例化Datagridview(在代码后面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!