Private Sub FormatDataGridView(ByVal dgvName As DataGridView) With dgvName If .RowCount < 1 Then Exit Sub .Font = New Font("Arial", 9, FontStyle.Regular) .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns("C1").DisplayIndex = 0 .Columns("C2").DisplayIndex = 1 .Columns("C3").DisplayIndex = 2 .Columns("C4").DisplayIndex = 3 .Columns("C5").DisplayIndex = 4 .Columns("C1").Width = 115 .Columns("C2").Width = 150 .Columns("C3").Width = 65 .Columns("C4").Width = 90 .Columns("C5").Width = 90 .Columns("C1").HeaderText = "H1" .Columns("C2").HeaderText = "H2" .Columns("C3").HeaderText = "H3" .Columns("C4").HeaderText = "H4" .Columns("C5").HeaderText = "H5" .Columns("C1").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft .Columns("C2").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft .Columns("C3").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft .Columns("C4").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("C5").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight .Columns("C5").DefaultCellStyle.Format = "#,###,##0.00" .Rows(0).DefaultCellStyle.Format = "#,###,##0.00" .Rows(1).DefaultCellStyle.Format = "#,###,##0.00" .Rows(2).DefaultCellStyle.Format = "#,###,##0.00" .Rows(3).DefaultCellStyle.Format = "#,###,##0.00" .Rows(4).DefaultCellStyle.Format = "#,###,##0.0000" .Columns("C6").Visible = False .Columns("C7").Visible = False End With End Sub
Friday, July 20, 2018
DataGridView Formatting
Labels:
DataGridView
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment