Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataGrid that displays various values, some of which can be edited in place when the user clicks on them. This is working fine except for one annoyance: at the moment, I have to click on the actual text already contained in a DataGridCell to begin editing, which sometimes can be a single character and so is difficult to hit.

Is there a way to get the DataGrid to begin a cell edit when the user clicks anywhere in a cell?

What I have tried:

I've found a few bits on the internet that seem to answer this question but I suspect they are out-of-date. For example, I found this statement "When I tested with the DataGrid that comes with WPF 4, I can click on anywhere in the cell," on this web page: wpfdatagrid - How can you set the clickable area of a WPF datagrid cell? - Stack Overflow[^]

... but I am definitely not seeing this behaviour. I am using WPF 4 according to what I see when I follow these steps: https://docs.microsoft.com/en-us/dotnet/framework/wpf/app-development/how-to-determine-the-installed-version-of-wpf
Posted
Updated 24-Oct-19 1:37am

1 solution

For once, the solution appears to be dead easy. Simply set DataGrid.SelectionUnit to Cell.

The whole control now seems more intuitive. I've even been able to remove some other XAML that I added to stop the whole row displaying a highlight that, at least for my use case, was confusing for the user.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900