Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good afternoon,

I am using a dataGridView to display some rows from a dataset, and with some calculated values also added in. The dataGrid view is populated using a DataView object, with some dataGridView fields populated using data that is calculated from other elements of the master DataSet.

In order to implement a total row at the bottom of the dataGridView, I have a checkbox field named "IsTotal". All "data" rows are set to false. The only one set to true is the total row, which will always be at the bottom.

I want the user to be able to sort the fields by click on the column headers, however the total row must always be at the bottom.

I have the solution half implemented by employing the Sorted event of the dataGridView.

In a nutshell, the event checks the field that the dataGridView has just been sorted by, and checks that it is not the "IsTotal" field (to prevent an infinate loop, caused by the event calling itself). If the dataGridView has just been sorted by a different field, it is resorted by the "IsTotal" field.

The sort works fine, but the dataGridView seems to loose it's old sorting completely. For example, if I sort by name and then sort by IsTotal, the rows should be sorted by IsTotal, and then by name. However, only the IsTotal field is sorted, the order after that sort has reverted back to it's default order.

Is there anyway to implement multi-level sorting programmatically?

Thanks.
Posted

Whenever your sorting is done,to keep your data in viewstate.During resort get the value from viewstate and sort the data and set binding to gridview.
 
Share this answer
 
Manivannan,

I do not understand what you mean. The DataGridView that I am using has data fed into it programatically.

Thanks.
 
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