Jump to content

Efeito de Mergecells no Datagridview do VB NET


Chamuanza
 Share

Recommended Posts

Oi Ribeiro

Aproveitando a tua resposta e no seguimento do topico andei a vasculhar pela net e encontrei esta classe.

Mas não sei se serve e não sei como aplicar no meu projecto

//
Public Class GroupByGrid
   Inherits DataGridView
   Protected Overrides Sub OnCellFormatting(ByVal args As DataGridViewCellFormattingEventArgs)
    MyBase.OnCellFormatting(args)
    ' First row always displays
    If args.RowIndex = 0 Then
	    Return
    End If
    If IsRepeatedCellValue(args.RowIndex, args.ColumnIndex) Then
	    args.Value = String.Empty
	    args.FormattingApplied = True
    End If
   End Sub
   Private Function IsRepeatedCellValue(ByVal rowIndex As Integer, ByVal colIndex As Integer) As Boolean
    Dim currCell As DataGridViewCell = Rows(rowIndex).Cells(colIndex)
    Dim prevCell As DataGridViewCell = Rows(rowIndex - 1).Cells(colIndex)
    If (currCell.Value Is prevCell.Value) OrElse (currCell.Value IsNot Nothing AndAlso prevCell.Value IsNot Nothing AndAlso currCell.Value.ToString() = prevCell.Value.ToString()) Then
	    Return True
    Else
	    Return False
    End If
   End Function
   Protected Overrides Sub OnCellPainting(ByVal args As DataGridViewCellPaintingEventArgs)
    MyBase.OnCellPainting(args)
    args.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
    ' Ignore column and row headers and first row
    If args.RowIndex < 1 OrElse args.ColumnIndex < 0 Then
	    Return
    End If
    If IsRepeatedCellValue(args.RowIndex, args.ColumnIndex) Then
	    args.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None
    Else
	    args.AdvancedBorderStyle.Top = AdvancedCellBorderStyle.Top
    End If
   End Sub

   Private Sub InitializeComponent()
    CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    CType(Me, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)
   End Sub
End Class

tenho um este form com uma datagridview que vai buscar os dadoa a uma tabela access

//
Public Class frmRoscasTabelaComposta

   Private Sub frmRoscasTabelaComposta_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'RoscasDataSet.TabRoscas' table. You can move, or remove it, as needed.
    Me.TabRoscasTableAdapter.Fill(Me.RoscasDataSet.TabRoscas)
   End Sub
   Private Sub btnSair_Click(sender As Object, e As EventArgs) Handles btnSair.Click
    Me.Close()
   End Sub
End Class
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.