Hi Guys,
I've got this code which causes a Null Reference exception
If I use this code it worksCode:If My.Computer.Keyboard.CtrlKeyDown Then If e.KeyCode = Keys.P Then If Me.DGJobLines.Columns("ClmLinePrice").Visible Then <---Here Me.DGJobLines.Columns("ClmLinePrice").Visible = False Else Me.DGJobLines.Columns("ClmLinePrice").Visible = True End If End If End If
Here is how the column is added to the grid, and yes there are other columns as well.Code:If My.Computer.Keyboard.CtrlKeyDown Then If e.KeyCode = Keys.P Then If Me.DGJobLines.Columns(2).Visible Then Me.DGJobLines.Columns(2).Visible = False Else Me.DGJobLines.Columns(2).Visible = True End If End If End If
Any Ideas?Code:Dim LinePriceCellStyle As New DataGridViewCellStyle With LinePriceCellStyle .Alignment = DataGridViewContentAlignment.MiddleRight .Format = "c2" .NullValue = "0.00" End With Dim ClmLinePrice As DataGridViewColumn = New DataGridViewTextBoxColumn With ClmLinePrice .Width = 50 .HeaderText = "Price" .DefaultCellStyle = LinePriceCellStyle .Visible = False End With Me.DGJobLines.Columns.Add(ClmLinePrice)
Fishy


Reply With Quote
