当前位置:编程学习 > C#/ASP.NET >>

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

用重绘方法,请详细说明一下,因为我用重绘方法还是问题,谢谢! --------------------编程问答-------------------- C#,winform  --------------------编程问答-------------------- 说明一下,是动态生成DATAGRIDVIEW,谢谢 --------------------编程问答-------------------- 等一下给你断代码 --------------------编程问答-------------------- 你是说把单元格合并在一起么? --------------------编程问答-------------------- 你在重绘单元格的时候读完一行之后把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;
                    }
                }

你看看对你有没有用吧,我没试验合并的功能觉得应该能实现功能 --------------------编程问答-------------------- 楼上的正解,楼主可以根据楼上的扩展一下,我就不给代码了,都差不多


但有点BUG,就是窗体移动太快的时候,会有点问题,不能及时删除再重绘 --------------------编程问答-------------------- 小菜来吼吼! --------------------编程问答-------------------- 楼上的小裤头不错,哪买的? --------------------编程问答--------------------    楼上应该悄悄地问阿,这里很多小朋友...... --------------------编程问答-------------------- 学习一下 --------------------编程问答-------------------- up --------------------编程问答-------------------- 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 --------------------编程问答-------------------- 来看看,正好现在有个需求也要用grid控件的,而且用到合并单元格 --------------------编程问答-------------------- 学习 --------------------编程问答-------------------- UP --------------------编程问答-------------------- 路过
--------------------编程问答-------------------- 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 --------------------编程问答-------------------- 改DataGridView中的属性SelectionMode改为FullRowSelect就变成选中全行了。 --------------------编程问答--------------------                    沉       默                       
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,