【问题标题】:Adding a checkbox-column to a WPF-datagrid which is linked to a datatable将复选框列添加到链接到数据表的 WPF 数据网格
【发布时间】:2014-05-09 01:39:47
【问题描述】:

我在将复选框列添加到 WPF 数据网格时遇到问题。

  1. 我创建了一个包含 8 列的数据表并使用 sql 填充它。
  2. 我使用 ItemsSource 将数据表绑定到 WPF 数据网格,例如:

    XAML:

    <DataGrid x:Name="dgOPListEntries" Grid.Row="1" Grid.ColumnSpan="2" Margin="5" ItemsSource="{Binding}" AutoGenerateColumns="True"></DataGrid>

    代码隐藏:

    dgOPListEntries.ItemsSource = dtOPListEntries.DefaultView;

到目前为止,这工作正常。

我现在想在数据网格中添加一个复选框列,我可以在其中选择一些行。 (选定的行随后将在 sql server 上更新。)

感谢任何帮助。

【问题讨论】:

    标签: c# wpf checkbox datagrid


    【解决方案1】:

    如果您只想选择一些行,您可以使用分别设置为DataGridSelectionMode.ExtendedDataGridSelectionUnit.FullRowDataGrid.SelectionModeDataGrid.SelectionUnit 属性。

    此外,DataGrid 会自动为 bool 类型的数据创建复选框列,如果您可以将字段添加到您的项目源。

    【讨论】:

      猜你喜欢
      • 2013-01-25
      • 2014-03-01
      • 2016-07-11
      • 2016-04-21
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      相关资源
      最近更新 更多