在DATAGRID中合并内容相同的单元格及实现行色彩交替

 

DATAGRID中合并内容相同的单元格及实现行色彩交替

经常在网上可以看到很多在DATAGRID中合并单元格的文章,感觉蛮不错的!
可是,我发现他不能实现按合并后的单元格实现“行”色彩交替
所以,就花了一些时间,研究了一下,终于能够在DATAGRID中实现合并单元格后
又能让其实现另类的行色彩交替。

Sub
SpanGrid()

        Dim i As Integer

        Dim j As Integer

        Dim intSpan As Integer

        Dim strTemp As String

        Dim flag As Boolean = True

        For i = 0 To DataGrid1.Items.Count - 1

            intSpan = 1

             strTemp = DataGrid1.Items(i).Cells(3).Text

            If flag = True Then

                DataGrid1.Items(i).BackColor = Color.LemonChiffon

                For j = i + 1 To DataGrid1.Items.Count - 1

                    If String.Compare(strTemp, DataGrid1.Items(j).Cells(3).Text) = 0 Then

                        intSpan += 1

                         DataGrid1.Items(i).Cells(3).RowSpan = intSpan

                        DataGrid1.Items(j).Cells(3).Visible = False

                         DataGrid1.Items(j).BackColor = Color.LemonChiffon

                    Else

                        Exit For

                    End If

                    flag = False

                Next

                i = j - 1

            Else

                DataGrid1.Items(i).BackColor = Color.LightYellow

                For j = i + 1 To DataGrid1.Items.Count - 1

                    If String.Compare(strTemp, DataGrid1.Items(j).Cells(3).Text) = 0 Then

                        intSpan += 1

                        DataGrid1.Items(i).Cells(3).RowSpan = intSpan

                        DataGrid1.Items(j).Cells(3).Visible = False

                         DataGrid1.Items(j).BackColor = Color.LightYellow

                    Else

                        Exit For

                    End If

                    flag = True

                Next

                i = j - 1

            End If

        Next

 

    End Sub

posted on 2005-01-27 16:39  №阿儒№  阅读(3962)  评论(10编辑  收藏  举报