Is it possible to make the last row of a DataGridView
as the sum of the columns, and that the last row always will show/be frozen?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Yes it is possible. Firstly you have to iterate through the grid and calculate the sum of the required columns after calculating the sums you have to create a new DataGridRow and populate it with the calculated values, set the Frozen property of the DataGridRow to True then add the new DataGridRow to the Datagridview. Sum Column Values in DataGridView
Instead of creating a new DataGridRow you could just add a new row with the summed values on your data source then find the last row on your DataGrid and set the property of that row to Frozen=True
To do this you have to set ShowFooter attribute of True
and then in code behind add your desire value in the footer
The solution is actually very simple, and just requires you to think outside the box a little.
Usually, once data is loaded into your grid view, there's a dark grey row at the bottom of it:
You can use this space to your advantage. All you need to do is drag a few labels onto your form, placed just inside your grid view, with a background colour applied:
Within your code, add a method like this:
Then, from wherever you update your grid view, call
UpdateTotal(labelPostsAffected, 2000);
, using the name of your label, and the sum you've calculated (or calculate it in the method).The result is something like this: