I am using WPF data-grid. In data-grid user have column-headers and row-headers.
When column-headers and row-headers both of them are visible, in the top left corner we have one small square section available. (cross section in the top left corner where the column and row headers meet.) when we click on that it selects all the cells within data-grid. Is there any event for that? If not how can trap that event. Please guide me.
Do let me know if you need any other information regarding this problem.
Regards, Priyank
It is not quite a nice solution, but you can handle an event like "SelectionChanged" and check if the number of selected items equals the number of items in your data source
I prefer to avoid using a code behind in views, so I've done it this way:
It is CheckBox on top left corner that select/unselect all.
The solution are built from 2 parts: Attached Properties and especial XAML structure:
1). Attached properties:
2) XAML:
The datagrid handles the routed command ApplicationCommand.SelectAll, so if the grid has focus and your press Ctrl-A, or you click the corner button, all cells are selected. You can handle this command yourself by adding a CommandBinding in xaml:
Or you can add the command binding in code:
However, there can only be a single handler for a routed command, so by default adding this handler this will prevent select all from working in the datagrid. In your handler you need therefore to call SelectAll.