[英]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.