wpf datagrid enter to edit
Asked Answered
N

1

2

I hope this is a simple one. I have a datagrid in a wpf application. one of the columns is a checkbox column. the user can only check the checkbox if the cell is already selected. so in effect to check any box the user has to double click, once to select, then once more to check the box. I want the user to be able to just check the box right a way with a single click. I couldn't find any obvious properties to make this happen. what's the best way to go about doing this?

News answered 13/6, 2011 at 21:56 Comment(1)
Possible duplicate #3427265Dislocate
M
2

For other answers see this SO post but the answer I liked was way at the bottom so I'll repeat it here with some more detail.

That answer was: don't use a DataGridCheckBoxColumn. It's almost no more work to just put a Checkbox in a DataGridTemplate Column. When you do this it responds to a single click exactly like you want. In the example below IsSelected is just a custom bool property on my ViewModel, everything else is pure xaml.

<DataGridTemplateColumn>
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <CheckBox  IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
    </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Moisesmoishe answered 19/10, 2011 at 0:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.