DataGridView控件页脚会总行的最佳实现。
来源:互联网 发布:nexus 跳过网络验证 编辑:程序博客网 时间:2024/06/14 10:08
大家一致在讨论如何做一个DataGridView控件汇总的行在最末,有的自己加上一行,把最后一行覆盖掉,有的在控件外部空间加上汇总的信息,都不是最佳的解决方案。
找到了一个老外的网址,才发现和人家比,我们还是有差距的。http://www.dotnetmonster.com/Uwe/Forum.aspx/winform-data-binding/1245/DataGridView-Summary-Row
用这个思路来解决DataGridView汇总行的问题,非常不错,排序等操作也不会影响最后一行,我梢后会扩展到以前发布的控件DataGridViewEx内http://download.csdn.net/detail/ireenter/3407133 ,到时分享给大家。
void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{///原文没有,但必需增加上。
this.dataGridView1.AllowUserToAddRows = true;
int sum = 0;
// only draw the cells of the extra row by ourselves, leaving the rest cells to the systemif (e.RowIndex == this.dataGridView1.NewRowIndex && e.ColumnIndex > -1)
{
for (int i = 0; i < this.dataGridView1.NewRowIndex; i++)
{
if (this.dataGridView1.Rows[i].Cells[e.ColumnIndex].Value.ToString().Trim() != "")
{
sum += (int)this.dataGridView1.Rows[i].Cells[e.ColumnIndex].Value;
}
}
e.PaintBackground(e.CellBounds, false);
e.Graphics.DrawString(sum.ToString(), this.dataGridView1.Font, Brushes.Black, e.CellBounds.Left + 2,e.CellBounds.Top + 2);
e.Handled = true;
}
}
- DataGridView控件页脚会总行的最佳实现。
- 缩放 Windows 窗体 DataGridView 控件的最佳做法
- Best Practices for Scaling the Windows Forms DataGridView Control(winform中控制DataGridView控件规模的最佳实践)
- 关于缩放 Windows 窗体 DataGridView 控件的最佳做法的介绍
- DataGridView控件的使用
- DataGridView控件的使用
- DataGridView控件的使用
- DataGridView控件的使用
- DataGridView控件的使用
- 获得GridView控件的总记录数(总行数)
- VS2005 自定义控件 Datagridview实现分页的源代码 (VB)
- C#实现WinForm下DataGridView控件的拷贝和粘贴
- 手动绑定BindingNavigator控件,用于实现DataGridView的导航
- 关于TextBox,Label,DataGridView等控件的鼠标拖动实现
- DataGridView控件中加入下拉框的编程实现
- WinForm下编写分页控件,实现DataGridView的分页效果
- WinForm控件设计:DataGridView的行统计实现
- dataGridView回车下一列的最佳方法
- Asp.net_DataTable的用法
- android 高通手机精品游戏合集
- 个人与集体的抉择
- No 122 · android获取本机号码和本机唯一标识
- vim显示行号、语法高亮、自动缩进的设置
- DataGridView控件页脚会总行的最佳实现。
- 网游开发的学习与杂绪
- 深入浅出REST
- java jdk
- JSP页面中的相对路径问题
- 一位在MIT教数学的老师总结了十条经验
- 读万卷书不如行万里路
- CTorrent程序源码分析
- 既然选择了远方,便只顾风雨兼程