【发布时间】:2016-09-22 20:23:04
【问题描述】:
我是 WPF 新手,正在尝试将程序从 WinForms 转换为 WPF。我在尝试从 DataGridView 转换为 DataGrid 并添加行时遇到了麻烦。任何帮助表示赞赏。
原码:
for (int i = 0; i < noteArray.Count; i++)
{
int newIndex = dtgrdNotes.Rows.Add();
dtgrdNotes.Rows[newIndex].Cells[0].Value = noteArray[i].ToString();
dtgrdNotes.Rows[newIndex].Cells[1].Value = chkbx1.Checked;
dtgrdNotes.Rows[newIndex].Cells[2].Value = chkbx2.Checked;
}
我需要该代码才能在 WPF 中工作,并且我尝试了 dtgrdNotes.Items 甚至 DataRowView 的不同变体,但到目前为止没有任何效果。有什么建议吗?
更新* XAML 与 Richard 的控件问题相关:
<DataGrid Name="dtgrdNotes" Height="178" Width="739" HorizontalAlignment="Right" VerticalAlignment="Bottom" Canvas.Left="1" IsEnabled="False" >
<DataGrid.Columns>
<DataGridTextColumn x:Name="dgtxtbxNote" Width="*" Binding="{Binding note}"/>
<DataGridCheckBoxColumn x:Name="dgchbxInquire" Width="100" Binding="{Binding inquire}" />
<DataGridCheckBoxColumn x:Name="dgchbxPrint" Width="100" Binding="{Binding print}" />
<DataGridTemplateColumn x:Name="dgbtncDelete" Width="80" Header="Button">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="dgbtncDeleteButton" Content="Delete" Width="50px" Height="10px" FontWeight="Bold" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
【问题讨论】:
标签: c# wpf datagridview datagrid