请教各位大叔大伯,Datagridview合并某一列时,为什么点击单元格文字会消失?

xuqunying0545 2010-09-02 11:07:24
private void dgvOnePerTimeInfo_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//纵向合并
if (this.dgvOnePerTimeInfo.Columns["EMP_NAMEFIRST"].Index == e.ColumnIndex && e.RowIndex >= 0)
{

using (
Brush gridBrush = new SolidBrush(this.dgvOnePerTimeInfo.GridColor),
backColorBrush = new SolidBrush(Color.WhiteSmoke)) // new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// 擦除原单元格背景
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
/**/
////绘制线条,这些线条是单元格相互间隔的区分线条,
////因为我们只对列name做处理,所以datagridview自己会处理左侧和上边缘的线条
if (e.RowIndex != this.dgvOnePerTimeInfo.RowCount - 1)
{
if (e.Value.ToString() != this.dgvOnePerTimeInfo.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString())
{

e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,
e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);//下边缘的线
//绘制值
if (e.Value != null)
{
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y-20, StringFormat.GenericDefault);//Crimson
}
}
}
else
{
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,
e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);//下边缘的线
//绘制值
if (e.Value != null)
{
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y-20, StringFormat.GenericDefault);
}
}
//右侧的线
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1,
e.CellBounds.Bottom - 1);

e.Handled = true;
}
}



}



}
...全文
153 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuqunying0545 2010-09-02
  • 打赏
  • 举报
回复
~~~~~~~~
xuqunying0545 2010-09-02
  • 打赏
  • 举报
回复
主要想合并后文字置中显示
xuqunying0545 2010-09-02
  • 打赏
  • 举报
回复
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y-20, StringFormat.GenericDefault);//Crimson
把这个改成了
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y+2, StringFormat.GenericDefault);//Crimson
文字显示在合并之后的最下方,且点击该合并单格不会消失,
为什么呢?
zerodegrees 2010-09-02
  • 打赏
  • 举报
回复
打酱油的,占座围观大叔大伯提供解决方案……

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧