datagridview 合并单元格

mike689689 2008-04-28 03:45:26
下面的代码实现静态的单元格合并(整列的单元格合并),但是我想实现的是如果上下行的第一列数据相同,只显示一行,如果不相同,两行都显示,不知道该如何改动?请不吝赐教。先谢谢了!(最终效果如下图)

70,000 | 70,000 1
50,000 | 50,000 1

     |   2      
|   3
100,000| 100,000 1
20,000 | 20,000 1
100 |100 1



静态的单元格合并代码如下
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cola As New DataGridViewRolloverCellColumn()
Dim colb As New DataGridViewRolloverCellColumn()
Dim colc As New DataGridViewRolloverCellColumn()
Dim cold As New DataGridViewRolloverCellColumn()
DataGridView1.Columns.Add(cola)
DataGridView1.Columns(0).Name = "a"
DataGridView1.Columns.Add(colb)
DataGridView1.Columns(1).Name = "b"
DataGridView1.Columns.Add(colc)
DataGridView1.Columns(2).Name = "c"
DataGridView1.Columns.Add(cold)
DataGridView1.Columns(3).Name = "d"
DataGridView1.Rows.Add(New Object() {"A1", "B1", "C1", "D1"})
DataGridView1.Rows.Add(New Object() {"A2", "B2", "C2", "D2"})
DataGridView1.Rows.Add(New Object() {"A3", "B3", "C3", "D3"})
End Sub
' GridViewCustomCell.vb
'This class will used at the data is filled to dataGridView.
'It is replace the default textboxcell. '*******************************************
Public Class GridViewCustomCell
Inherits DataGridViewTextBoxCell
Private lisDoubleLeftLine As Boolean
Private lisSigTopLine As Boolean
Private lisSigButtomLine As Boolean
'''' ''' ''' ''' ''' ''' '''
''''
Public Sub New()
'ByVal isDoubleLeftLine_In As Boolean, _ '这个参数一加就挂,所以把它们屏蔽掉了
'ByVal isSigTopLine_In As Boolean, _
'ByVal isSigButtomLine_In As Boolean _
')
'lisDoubleLeftLine = isDoubleLeftLine_In
'lisSigTopLine = isSigTopLine_In
'lisSigButtomLine = isSigButtomLine_In
End Sub
Public Sub myLine( _
ByVal isDoubleLeftLine_In As Boolean, _
ByVal isSigTopLine_In As Boolean, _
ByVal isSigButtomLine_In As Boolean _
)
lisDoubleLeftLine = isDoubleLeftLine_In
lisSigTopLine = isSigTopLine_In
lisSigButtomLine = isSigButtomLine_In
End Sub

''' ''' ''' ''' ''' ''' ''' ''' ''' ''' borderStylePlaceHolder '''
'''
Public Overrides Function AdjustCellBorderStyle( _
ByVal borderStyleInput_In As DataGridViewAdvancedBorderStyle, _
ByVal borderStylePlaceHolder_In As DataGridViewAdvancedBorderStyle, _
ByVal verticalBorderAdded_In As Boolean, _
ByVal horizontalBorderAdded_In As Boolean, _
ByVal firstVisibleColumn_In As Boolean, _
ByVal firstVisibleRow_In As Boolean _
) As DataGridViewAdvancedBorderStyle
If lisDoubleLeftLine = True Then

borderStylePlaceHolder_In.Left = _
DataGridViewAdvancedCellBorderStyle.InsetDouble
Else
borderStylePlaceHolder_In.Left = _
DataGridViewAdvancedCellBorderStyle.None
End If
borderStylePlaceHolder_In.Right = _
borderStyleInput_In.Right
If lisSigTopLine = True Then

borderStylePlaceHolder_In.Top = _
borderStyleInput_In.Top
Else
borderStylePlaceHolder_In.Top = _
DataGridViewAdvancedCellBorderStyle.None
End If
If lisSigButtomLine = True Then


borderStylePlaceHolder_In.Bottom = _
borderStyleInput_In.Bottom
Else
borderStylePlaceHolder_In.Bottom = _
DataGridViewAdvancedCellBorderStyle.None
End If
Return borderStylePlaceHolder_In
End Function
End Class

Public Class DataGridViewRolloverCellColumn
Inherits DataGridViewColumn
Public Sub New()
'ByVal isDoubleLeftLine_In As Boolean, _
'ByVal isSigTopLine_In As Boolean, _
'ByVal isSigButtomLine_In As Boolean _
')
Me.CellTemplate = New GridViewCustomCell()
'False, _
'False, _
'False)
End Sub

End Class

...全文
1267 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanjs 2009-06-13
  • 打赏
  • 举报
回复
没注释,看不懂.
xuzhenlei123 2009-04-25
  • 打赏
  • 举报
回复
学习下
hanyu0528 2008-07-30
  • 打赏
  • 举报
回复
学习
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
没遇到过这种情况.
mike689689 2008-04-30
  • 打赏
  • 举报
回复
多谢各位“顶”兄和解答的姑娘,现在结贴
mike689689 2008-04-29
  • 打赏
  • 举报
回复
多谢兄台(还是应该叫姑娘?)指引,稍后我试试,十分感谢!
firein 2008-04-29
  • 打赏
  • 举报
回复
使用:

dgdShoninData.Rows(1).Cells(1) = _
New GridViewCustomCellAIJ02412001(False, False)
firein 2008-04-29
  • 打赏
  • 举报
回复

Public Class GridViewCustomCellAIJ02412001
Inherits DataGridViewTextBoxCell

Private lisSigTopLine As Boolean = False
Private lisSigButtomLine As Boolean = False



Public Sub New( _
ByVal isSigTopLine_In As Boolean, _
ByVal isSigButtomLine_In As Boolean)

lisSigTopLine = isSigTopLine_In
lisSigButtomLine = isSigButtomLine_In

End Sub


Public Overrides Function AdjustCellBorderStyle( _
ByVal borderStyleInput_In As DataGridViewAdvancedBorderStyle, _
ByVal borderStylePlaceHolder_In As DataGridViewAdvancedBorderStyle, _
ByVal verticalBorderAdded_In As Boolean, _
ByVal horizontalBorderAdded_In As Boolean, _
ByVal firstVisibleColumn_In As Boolean, _
ByVal firstVisibleRow_In As Boolean _
) As DataGridViewAdvancedBorderStyle

borderStylePlaceHolder_In.Left = DataGridViewAdvancedCellBorderStyle.None

borderStylePlaceHolder_In.Right = borderStyleInput_In.Right

If lisSigTopLine = True Then
borderStylePlaceHolder_In.Top = _
borderStyleInput_In.Top
Else
borderStylePlaceHolder_In.Top = _
DataGridViewAdvancedCellBorderStyle.None
End If

If lisSigButtomLine = True Then
borderStylePlaceHolder_In.Bottom = _
borderStyleInput_In.Bottom
Else
borderStylePlaceHolder_In.Bottom = _
DataGridViewAdvancedCellBorderStyle.None
End If

Return borderStylePlaceHolder_In

End Function

End Class
firein 2008-04-29
  • 打赏
  • 举报
回复
你如果想自己控制的话就不能用DataGridViewRolloverCellColumn了

列先定义好(系统的)

然后通过遍历数据 一个一个的加cell
firein 2008-04-29
  • 打赏
  • 举报
回复
呵呵 这个我做过 不是真正的合并 只是把线隐藏了 看上去合并了
mike689689 2008-04-28
  • 打赏
  • 举报
回复
各位高手,c#的也可以,只要大虾们能实现就好,只要是.net的都可以,拜托各位大虾了!!
急用!!
beblue 2008-04-28
  • 打赏
  • 举报
回复
偶学C shape的,,,帮顶
rockyvan 2008-04-28
  • 打赏
  • 举报
回复
关注
cpw999cn 2008-04-28
  • 打赏
  • 举报
回复
sorry,我們C#的~
zhu_gx 2008-04-28
  • 打赏
  • 举报
回复
这里人少,帮LZ再顶一下吧
zhu_gx 2008-04-28
  • 打赏
  • 举报
回复
先顶一个
mike689689 2008-04-28
  • 打赏
  • 举报
回复
这么没人啊……
高手都哪去了……
顺便说一下,效果图的纵向应该是根据”|”对齐的,这里没画好

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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