各位大哥大姐,请教一下,C# DataGridView中如何合并某一行所有单元格?小妹先谢了

xuqunying0545 2010-01-15 09:35:29
用重绘方法,请详细说明一下,因为我用重绘方法还是问题,谢谢!
...全文
338 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dxiaojie 2010-11-22
  • 打赏
  • 举报
回复
沉 默
daichenghua 2010-01-15
  • 打赏
  • 举报
回复
学习一下
freetd 2010-01-15
  • 打赏
  • 举报
回复
楼上应该悄悄地问阿,这里很多小朋友......
  • 打赏
  • 举报
回复
楼上的小裤头不错,哪买的?
cena_jin 2010-01-15
  • 打赏
  • 举报
回复
小菜来吼吼!
liushengmz 2010-01-15
  • 打赏
  • 举报
回复
楼上的正解,楼主可以根据楼上的扩展一下,我就不给代码了,都差不多


但有点BUG,就是窗体移动太快的时候,会有点问题,不能及时删除再重绘
dapsxianfeng2010 2010-01-15
  • 打赏
  • 举报
回复
你在重绘单元格的时候读完一行之后把e.CellBounds的宽度之和 以及高度作为一个矩形的宽,高度就是行高,然后把内容绘制在中间,你试试吧

if (e.RowIndex >= 0)
{
Rectangle newRect = new Rectangle(e.CellBounds.X + 1,e.CellBounds.Y + 1, e.CellBounds.Width - 4,e.CellBounds.Height - 4);
using (Brush gridBrush = new SolidBrush(this.SymbolViewList.GridColor),backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
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);
e.Graphics.DrawRectangle(Pens.Black, newRect);
if (e.Value != null)
{
if (e.Value.ToString().Length != 0)
{
if (e.RowIndex == rowIndext && e.ColumnIndex == colIndex)//当前被选中的单元格
{
e.Graphics.FillRectangle(Brushes.Orange, e.CellBounds);
}

e.Graphics.DrawString(Convert.ToString(((Image)e.Value).Tag), e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 50, e.CellBounds.Y + 95, StringFormat.GenericDefault);

e.Graphics.DrawImage((Image)e.Value, new Point(e.CellBounds.X, e.CellBounds.Y));
}
}
e.Handled = true;
}
}

你看看对你有没有用吧,我没试验合并的功能觉得应该能实现功能
dapsxianfeng2010 2010-01-15
  • 打赏
  • 举报
回复
你是说把单元格合并在一起么?
dapsxianfeng2010 2010-01-15
  • 打赏
  • 举报
回复
等一下给你断代码
xuqunying0545 2010-01-15
  • 打赏
  • 举报
回复
说明一下,是动态生成DATAGRIDVIEW,谢谢
xuqunying0545 2010-01-15
  • 打赏
  • 举报
回复
C#,winform
SUMMERMUSIC 2010-01-15
  • 打赏
  • 举报
回复
改DataGridView中的属性SelectionMode改为FullRowSelect就变成选中全行了。
Lucky_6Q 2010-01-15
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090630/18/b2681fb1-e17a-48da-b946-3ac2cbdb6f85.html?56681
http://topic.csdn.net/u/20091129/11/ea282703-d51b-4fe9-b663-f1331a56325f.html
liji2009 2010-01-15
  • 打赏
  • 举报
回复
路过
hangang7403 2010-01-15
  • 打赏
  • 举报
回复
UP
清明_ 2010-01-15
  • 打赏
  • 举报
回复
学习
nashina 2010-01-15
  • 打赏
  • 举报
回复
来看看,正好现在有个需求也要用grid控件的,而且用到合并单元格
happyboyxq1985 2010-01-15
  • 打赏
  • 举报
回复
up

110,533

社区成员

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

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

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