【问题标题】:How to disable a column selection in DataGrid WPF?如何禁用 DataGrid WPF 中的列选择?
【发布时间】:2011-07-07 14:19:05
【问题描述】:

我的数据网格中有这一列

<DataGridTemplateColumn Header="Delete" IsReadOnly="True" >
    <DataGridTemplateColumn.CellStyle>
     <Style TargetType="DataGridCell">
       <Setter Property="Background" Value="Transparent"/>
       <Setter Property="BorderBrush" Value="Transparent"/> 
      </Style>
       <DataGridTemplateColumn.CellStyle>
        <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
        <CheckBox IsChecked="{Binding Delete, UpdateSourceTrigger=PropertyChanged, 
         Mode=TwoWay}" />
         </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>

我想禁用此列的选择,因为如果用户单击此列,则其行上的其他单元格也会被选中。因此,我想禁用此列选择,但允许复选框保持启用状态。

【问题讨论】:

    标签: c# wpf xaml datagrid


    【解决方案1】:

    为数据网格改变它,所以它的

    <DataGrid SelectionUnit="CellOrRowHeader">
    

    这应该允许您选择单个单元格

    【讨论】:

    • 它有效,但我必须修改数据网格上的事件触发器,然后从集合中获取行的标题,如果它的“删除”我不会设置所选项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 2019-02-14
    相关资源
    最近更新 更多