[英]using DataGridView(winForms) in wpf
我在wpf应用程序中使用datagridview(不是datagrid),并且我使用此代码在Window中调用它
<Window x:Class="TestHosting.MainWindow"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="440.132" Width="521.053">
<Grid>
<WindowsFormsHost Margin="20,20,130,142">
<wf:DataGridView x:Name="dgv">
<wf:DataGridView.Columns>
<wf:DataGridViewColumn Name="column1" HeaderText="Col l" />
<wf:DataGridViewColumn Name="column2" HeaderText="Col 2"/>
<wf:DataGridViewColumn Name="column3" HeaderText="Col 3"/>
</wf:DataGridView.Columns>
</wf:DataGridView>
</WindowsFormsHost>
问题是一个错误表明“至少在datagridview控件的列中没有单元格模板。”
我该如何解决该错误?
您可以使用DataGrid ,而不是DataGridView
SqlDataAdapter da = new SqlDataAdapter("Select * from Table", con);
DataTable dt = new DataTable("Call Reciept");
da.Fill(dt);
DataGrid dg = new DataGrid();
dg.ItemsSource = dt.DefaultView;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.