How can I disable editing cells in a WPF Datagrid?

2019-02-01 15:23发布

I'm constructing a datagrid in Windows Presentation Foundation, and I have a problem. When a user double-clicks on a cell in my datagrid, the cell goes into edit mode. I want to prevent that. Instead I want users to be able to select the full row - not edit values in it.

How can I make it so that double-clicks select the full row instead of putting the clicked-on cell in edit mode?

3条回答
别忘想泡老子
2楼-- · 2019-02-01 15:52

The DataGrid has an XAML property IsReadOnly that you can set to true:

<my:DataGrid
    IsReadOnly="True"
/>
查看更多
孤傲高冷的网名
3楼-- · 2019-02-01 16:04

The WPF DataGrid has an IsReadOnly property that you can set to True to ensure that users cannot edit your DataGrid's cells.

You can also set this value for individual columns in your DataGrid as needed.

查看更多
欢心
4楼-- · 2019-02-01 16:11

If you want to disable editing the entire grid, you can set IsReadOnly to true on the grid. If you want to disable user to add new rows, you set the property CanUserAddRows="False"

<DataGrid IsReadOnly="True" CanUserAddRows="False" />

Further more you can set IsReadOnly on individual columns to disable editing.

查看更多
登录 后发表回答