如何绑定数据表到Datagrid的 [英] How to bind DataTable to Datagrid
本文介绍了如何绑定数据表到Datagrid的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,一个数据表
绑定到的DataGrid
。我已经搜索了解决方案,但就是无法摆脱的错误。的精致的结合使用的作品时WindowsForms,因此数据表
是正确的。的我只是不能将其绑定到WPF的DataGrid中。
I have a problem binding a DataTable
to a DataGrid
. I have already searched for solutions but just can't get rid of the error. The binding works fine when using WindowsForms, so the DataTable
is correct. I just can't bind it to a WPF-DataGrid.
错误消息: AmbiguousMatchException是未处理的结果
来源:mscorlib程序
Error message: AmbiguousMatchException was unhandled
Source: mscorlib
我已经成立了新的项目,以摆脱任何不良链接等。
I have already set up new project to get rid of any bad links, etc.
XAML- code:
<DataGrid x:Name="grid1" Margin="10" ItemsSource="{Binding}"
AutoGenerateColumns="True"></DataGrid>
我已经尝试下面的C# - 落后code:
grid1.ItemsSource = dt.DefaultView;
或
grid1.DataContext = dt.DefaultView;
或
grid1.DataContext = dtex;
任何帮助是AP preciated。
Any help is appreciated.
推荐答案
在CS文件
DataTable employeeData = CreateDataTable();
gridEmployees.DataContext = employeeData.DefaultView;
在XAML文件
<DataGrid Name="gridEmployees" ItemsSource="{Binding}">
这篇关于如何绑定数据表到Datagrid的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文