casio888
casio888

Reputation: 13

Stop sorting of WPF dataGrid once

I want to show a new window over the position of the column I clicked. In the window will be decided, if either the content of the dataGrid gets filtered or the dataGrid will be sorted by the clicked column.

When the ColumnHeader of a dataGrid is clicked the content in the dataGrid gets sorted by default. I tried to setting the "CanUserSortColumns"-property of the dataGrid to false. But I cant find an event that triggers after the sorting of the dataGrid to enable the sorting again. I have tried Click, PrewievMouseUp, MouseUp, Loaded and TargetUpdated so far.

The "Click" event of the ColumnHeader will still trigger, so I could enable the sorting, but if "CanUserSortColumns" is disabled, there is no sufficient visual Indicator while hovering the ColumnHeader.

Upvotes: 1

Views: 596

Answers (1)

Yevgeniy
Yevgeniy

Reputation: 1066

Try to use Sorting event:

DataGrid.Sorting += DataGridOnSorting;

And put your window logic in handler:

private void DataGridOnSorting(object sender, DataGridSortingEventArgs e)
{
    // Your window logic.
    e.Handled = true;
}

Upvotes: 2

Related Questions