Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable editing cells in a WPF Datagrid?

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?

like image 914
Pouyan Avatar asked Jul 20 '11 18:07

Pouyan


People also ask

How do you make an editable grid in WPF?

You can set the properties CanUserAddRows to true to allow user to add rows. DataGrid is editable by default, where each column has an edit control which lets you edit its value. By default the DataGrid automatically generates columns for every property in your Model, so you don't even have to define it's columns.

What is the difference between grid and DataGrid in WPF?

A Grid is a control for laying out other controls on the form (or page). A DataGrid is a control for displaying tabular data as read from a database for example.

Can user add rows DataGrid WPF?

WPF DataGrid (SfDataGrid) provides built-in row called AddNewRow. It allows user to add a new row to underlying collection.


1 Answers

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.

like image 89
Leslie Davies Avatar answered Oct 18 '22 14:10

Leslie Davies