[CLOSED] How to show Totals for DataGridView?

Closed
0
0

Hi Team,

I am using “Wisej2 Free trial” , I created application with Wisej Web Application. In this application their is no Footer for DataGridview column
Here We are adding new dynamic row for Totals, and showing the calculated Totals in new row. But the Problem is whenever we sort the column the Total row is going up. I want to show the total row in Footer. I don’t want to sort this Total row. Can you please help me on this.

 

Thanks
Sushma Konda

Attachment
  • You must to post comments
0
0

Hi Sushma Konda

 

I would add another datagridview with one only row under your grid for the totals.

 

Greetings!!.

  • You must to post comments
0
0

You can also make the summary row sort to the bottom by handling the SortCompare event. If you add a custom DataGridRow class you can check the type, or you can add a Tag value and check that. Otherwise use our DataGridViewSummaryRows extension. See attached sample.

To add a summary row on all columns use:

 for (var i = 0; i < grid.ColumnCount; i++)
 {
    grid.AddSummaryRows(SummaryType.Sum, SummaryRowPosition.Below, null, null, grid.Columns[i], style);
 }

The extension handles different summary types, grouping, nesting, etc.

To make the summary row sort to the bottom use:

 private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
 {
    var grid = (DataGridView)sender;
    var order = grid.SortOrder == SortOrder.Descending ? -1 : 1;
    if (grid.Rows[e.RowIndex1] is DataGridViewSummaryRow)
    {
       e.Handled = true;
       e.SortResult = order;
    }
    if (grid.Rows[e.RowIndex2] is DataGridViewSummaryRow)
    {
       e.Handled = true;
       e.SortResult = -order;
    }
 }

 

HTH

  • sushma konda
    Thanks for responding Luca.
  • sushma konda
    Iam getting error like row cannot be added programmatically to the grid view. can you please help me out.
  • You must to post comments
0
0

Hi Luca,

I tried the provided Example in mycode but getting below error. Please help me on this.

 

  • You must to post comments
0
0

You can’a add a row directly to a DataGridView that is bound to a data source. The index of the rows would get out of sync. It’s the same in Winforms. In your original message you wrote that you added a dynamic row. I think you can still use the SortCompare event to control the sorting order. Otherwise please attach a small runnable sample app.

  • You must to post comments
Showing 4 results