0

Saludos a la comunidad.

Tengo una consulta con respecto a la agrupación de un DataTable, pasa que tengo el siguiente DataTable:

foto1

Requeriría hacer algo como lo siguiente:

FOTO2

Donde cuando haga clic en el checkbox del nuevo NroOrden seleccione todo su grupo; lo que estuve intentado es lo siguiente:

.Columns("NroOrden").SortMode = DataGridViewColumnSortMode.NotSortable

Pero lo anterior, no funciona y no tengo mucha experiencia en VB.NET. Espero puedan apoyarme. Saludos a todos.

1 respuesta 1

0

Solucionado. Al parecer es una función MERGE que es "estándar" en muchos casos, se puede encontrar en varios foros como en este también.

Lo que hace realmente no es agrupar sino que elimina las líneas de las celdas de los valores repetidos (la columna por la que quieres agrupar) y luego pareciera un efecto de agrupamiento por esa columna. Pero todo es un efecto visual.

Se las dejo a fin de que a alguien le sirva:

Private Sub dgvNeumaticos_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DgvNeumaticos.CellPainting
        If BtnVistaPorFacturar.Checked Then
            If DgvNeumaticos.Columns(e.ColumnIndex).Name = "NroOrden" AndAlso e.RowIndex <> -1 Then

                Using gridBrush As Brush = New SolidBrush(DgvNeumaticos.GridColor), backColorBrush As Brush = New SolidBrush(e.CellStyle.BackColor)

                    Using gridLinePen As Pen = New Pen(gridBrush)
                        ' Clear cell   
                        e.Graphics.FillRectangle(backColorBrush, e.CellBounds)

                        ' Draw line (bottom border and right border of current cell)   
                        'If next row cell has different content, only draw bottom border line of current cell   
                        If e.RowIndex = DgvNeumaticos.Rows.Count - 1 OrElse
                            (e.RowIndex < DgvNeumaticos.Rows.Count - 2 AndAlso DgvNeumaticos.Rows(e.RowIndex + 1).Cells(e.ColumnIndex).Value.ToString() <> e.Value.ToString()) Then
                            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1)

                        End If

                        ' Draw right border line of current cell   
                        e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom)

                        ' draw/fill content in current cell, and fill only one cell of multiple same cells   
                        If Not e.Value Is Nothing Then
                            If e.RowIndex > 0 AndAlso DgvNeumaticos.Rows(e.RowIndex - 1).Cells(e.ColumnIndex).Value.ToString() = e.Value.ToString() Then
                            Else
                                e.Graphics.DrawString(CType(e.Value, String), e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 5, StringFormat.GenericDefault)
                            End If
                        End If

                        e.Handled = True
                    End Using
                End Using
            End If
        End If
    End Sub

Resultado final:

finalResult

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.