Nivid Dholakia
Nivid Dholakia

Reputation: 5462

How to disable a column selection in DataGrid WPF?

I have this column in my datagrid

<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>

I want to disable the selection of this column since, if the user clicks on this column, other cells on its row get selected too. Therefore, I want to disable this column selection but the allow the checkbox to remain enabled.

Upvotes: 1

Views: 2790

Answers (1)

Manatherin
Manatherin

Reputation: 4187

for the data grid change it so its

<DataGrid SelectionUnit="CellOrRowHeader">

that should allow you to select individual cells

Upvotes: 1

Related Questions