winForm中如何实现这样的效果
查询时,如何在DataGrid中显示出如下的表头
___________________________________
| 合 计 |
|_________________________________|
|1999年度 | 2000年度 |
|_______________ |________________|
如果有第三方控件请告之小弟下载地址,拒绝web模式
查询时,如何在DataGrid中显示出如下的表头
___________________________________
| 合 计 |
|_________________________________|
|1999年度 | 2000年度 |
|_______________ |________________|
如果有第三方控件请告之小弟下载地址,拒绝web模式
解决方案 »
- 帮忙看一下
- C# 中如何实现 点击按钮返回 cmd route print 命令 查看本机静态路由
- 大家帮帮忙
- 求一个用dateset更新数据的方法
- C# 进度条问题。
- 警告 因为这是一个静态事件,所以释放应用程序时必须分离事件处理程序,否则会导致内存泄漏。
- Dataset绑定高手帮忙!谢谢!在线等!解决立刻给分!!!!!!!!!!!
- C#调用C++的dll的问题
- 如何使用键盘Hook,用于控制台
- 请问《windows 程序设计》160rmb 对学习c#有帮助吗??请推荐几本C#入门级的好书
- udp socket 多线程通信问题。。急。。。。
- OpenFileDialog 打开文件释放后仍然进程占用?
在CellPainting事件里面重绘
http://www.cnblogs.com/xiongeee/archive/2007/03/08/667962.html
{
// 对第1列相同单元格进行合并
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
using
(
Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
backColorBrush = new SolidBrush(e.CellStyle.BackColor)
)
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// 清除单元格
e.Graphics.FillRectangle(backColorBrush, e.CellBounds); // 画 Grid 边线(仅画单元格的底边线和右边线)
// 如果下一行和当前行的数据不同,则在当前的单元格画一条底边线
if (e.RowIndex < dataGridView1.Rows.Count - 1 &&
dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() !=
e.Value.ToString())
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
e.CellBounds.Bottom - 1);
// 画右边线
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1,
e.CellBounds.Bottom); // 画(填写)单元格内容,相同的内容的单元格只填写第一个
if (e.Value != null)
{
if (e.RowIndex > 0 &&
dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() ==
e.Value.ToString())
{ }
else
{
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y + 5, StringFormat.GenericDefault);
}
}
e.Handled = true;
}
}
}
}
不过这样的话,数据多的时候,性能会受到点影响可以的话,尽量改其它控件吧
http://blog.csdn.net/manimanihome/archive/2008/03/31/2233573.aspx
http://blog.csdn.net/teacatcn/archive/2008/01/23/2060482.aspx
{
// 对第1列相同单元格进行合并
if (e.ColumnIndex == 0 && e.RowIndex != -1)
{
using
(
Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
backColorBrush = new SolidBrush(e.CellStyle.BackColor)
)
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// 清除单元格
e.Graphics.FillRectangle(backColorBrush, e.CellBounds); // 画 Grid 边线(仅画单元格的底边线和右边线)
// 如果下一行和当前行的数据不同,则在当前的单元格画一条底边线
if (e.RowIndex < dataGridView1.Rows.Count - 1 &&
dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() !=
e.Value.ToString())
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
e.CellBounds.Bottom - 1);
// 画右边线
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1,
e.CellBounds.Bottom); // 画(填写)单元格内容,相同的内容的单元格只填写第一个
if (e.Value != null)
{
if (e.RowIndex > 0 &&
dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() ==
e.Value.ToString())
{ }
else
{
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y + 5, StringFormat.GenericDefault);
}
}
e.Handled = true;
}
}
}
}
不过这样的话,数据多的时候,性能会受到点影响 可以的话,尽量改其它控件吧
参考
http://www.cnblogs.com/xzcxlyh/archive/2007/03/10/664049.html
http://blog.csdn.net/zhangzeshuai/archive/2008/09/12/2916103.aspx
这里面有个自定义表头的类,直接引用就可以了,支持多级表头
呵呵