学无止境

Life-long learning
posts - 57, comments - 21, trackbacks - 0, articles - 0
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

合并DataGird列中相同的列

Posted on 2008-08-12 14:08 anytime8 阅读(45) 评论(0) 编辑 收藏

    Private Sub SpanGrid()
        Dim i, j, m As Integer
        Dim intSpan As Integer, NowSpan As Integer = 0
        Dim strTemp, temp As String

        For m = 0 To 1
            NowSpan = 0
            For i = 0 To Grid_List.Items.Count - 1
                intSpan = 1
                strTemp = Grid_List.Items(i).Cells(m).Text
                For j = i + 1 To Grid_List.Items.Count - 1
                    temp = Grid_List.Items(j).Cells(m).Text
                    If String.Compare(strTemp, temp) = 0 Then
                        intSpan += 1
                        Grid_List.Items(i).Cells(m).RowSpan = intSpan
                        Grid_List.Items(j).Cells(m).Visible = False
                    Else
                        Exit For
                    End If
                Next

                NowSpan += intSpan
                i = NowSpan - 1
            Next
        Next

    End Sub