Click here to Skip to main content
14,453,814 members
Rate this:
Please Sign up or sign in to vote.
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 2:37am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100