开发者

wpf datagrid enter to edit

开发者 https://www.devze.com 2023-03-12 10:13 出处:网络
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 chec

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 thi开发者_如何学编程s happen. what's the best way to go about doing this?


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

精彩评论

暂无评论...
验证码 换一张
取 消