这是我的dataGridview结果:
以及我的期望:
我想合并第一列中相等的单元格。我使用此代码:
Private Sub DataGridView2_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView2.CellPainting
If e.RowIndex = 0 Then
If (DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then
If (e.ColumnIndex = 0) Then
DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value = ""
e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
End If
End If
End If
If e.RowIndex > 0 Then
If e.RowIndex < DataGridView2.Rows.Count - 2 Then
If (DataGridView2.Rows(e.RowIndex - 1).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString()) Then
If (e.ColumnIndex = 0) Then
DataGridView2.Rows(e.RowIndex).Cells(0).Value = ""
e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None
End If
End If
If (DataGridView2.Rows(e.RowIndex).Cells(0).Value.ToString() = DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value.ToString()) Then
If (e.ColumnIndex = 0) Then
DataGridView2.Rows(e.RowIndex + 1).Cells(0).Value = ""
e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None
End If
End If
End If
End If
End Sub
它可以工作但是当我选择一行时,会被破坏。另外,我想用红线分隔每组的数据。另外在顶部单元格中绘制对角线并写下名称。