DataGridView - ColumnHeaderMouseClick event

Answered
0
0

Using version 2.2.44.0

Would it be possible to make the ColumnHeaderMouseClick event (which initiates sorting) fire before the DefaultValuesNeeded event?

Currently it fires after the Event causing an inconsistency between updating existing rows and adding new rows.

Technically the DefaultValuesNeeded populates default values in the empty row which is necessary if your DGV is data bound.

Arguably why does the DefaultValuesNeeded fire anyway when a column header is clicked, given empty row already has its values?

Alternatively is it possible to have a UserRequestedSorting event?

Thanks for your help

  • You must to post comments
Best Answer
0
0

You can set the ColumnSortMode to Programmatic. This way you get the ColumnHeaderMouseClick before any sorting, then simply call Sort(). You’ll have to keep track of the sort order.

The automatic row is removed before sorting and re-added after sorting, requesting the default values.

When ColumnSortMode is set to Auto the sorting is not triggered by the ColumnHeaderMouseClick. It’s part of the client side data request. I.e. the datagrid widget requests rows from 50 to 100 sorted by col1 descending. The data request is processed independently from the user events.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.