-Wing-
New member
I am having a problem with all the columns in a DGV where if the Grid is reloaded I lose one of the columns until only one column is left. But if I remove a section of the code, it works as expected. Here is the code. The portion that is commented out is the section that affects the dissappearing column.
I will only be able to view post for the next 9 hours but can respond to post. I appreciate any help that can be given.
VB.NET:
Private Sub BuildCharges(ByVal theSQL As String) 'Fill Charges DataGridView
On Error GoTo ErrorTrack
Dim ChargesTable As New DataTable
ChargesTable = TC.GetInfo(theSQL)
If ChargesTable.Rows.Count > 0 Then
Dim BS As New BindingSource
BS.DataSource = ChargesTable
With ChargesDG
.DataSource = BS
.Columns(0).Visible = False
.Columns(1).Visible = False
.Columns(2).Visible = False
.Columns(3).HeaderText = "Charge"
.Columns(4).HeaderText = "Amount"
.Columns(4).DefaultCellStyle.Format = "c"
.Columns(5).Visible = False
.Columns(6).Visible = False
.AutoResizeColumns()
.AutoResizeColumnHeadersHeight()
.RowHeadersVisible = False
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None
.BorderStyle = BorderStyle.None
End With
'If TC.strLevel < 1 Then
' Dim DelButton As New DataGridViewButtonColumn()
' With DelButton
' .HeaderText = "Delete"
' .Text = "Delete"
' .UseColumnTextForButtonValue = True
' .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
' .FlatStyle = FlatStyle.Standard
' .CellTemplate.Style.BackColor = Color.Honeydew
' End With
' ChargesDG.Columns.Add(DelButton)
'End If
ChargesDG.Visible = True
lblCharges.Text = ""
Else
ChargesDG.Visible = False
lblCharges.Text = "No Charges have been applied."
End If
ChargesTable = Nothing
Exit Sub
ErrorTrack:
TC.ErrorLog(Err.Erl, Err.Description, Me.Name.ToString, "BuildCharges", TC.strSQL)
MsgBox("A Critical Error has occurred." & vbNewLine & "A log file has been created." & vbNewLine & "Please contact the " & _
"software author." & vbNewLine & "The Application will now close.", MsgBoxStyle.Critical, "Tuition Care - Application Error")
Application.Exit()
End Sub