Saturday, 18 July 2015

How to group by Data group by in datagrid view in vb.net

I searched the solutions to group data in datagridview. Here is the best and easiest solution I found.

    Private Sub dgvItemList_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvItemList.CellFormatting
        If e.RowIndex > 0 And e.ColumnIndex = 3 Then
            If Me.dgvItemList.Item(3, e.RowIndex - 1).Value = e.Value Then
                e.Value = ""
            End If
        End If

        If e.Value.ToString <> "" And e.ColumnIndex = 3 Then
            e.CellStyle.BackColor = Color.SkyBlue
        End If
    End Sub

Reference :
http://www.vb-tips.com/DataGridViewGrouping.aspx