hi. am back and i got another problem with this selectionchanged event in datagridview1
i set my datagridview1 to
Selectionmode = fullrowselect
the problem is i got nullreferenceexception error whenever i clicked the column header
so meaning selectionchanged fire when i click the columnheader
since columnheader will have a row value of null
the exception appears
i tried to catch it but ending up in messy situation which the
code i written doesn't run right.
is there anyway to prevent user from clicking column header but it still visible?
but if i do that user cant sort the data right..
thanks for helping outCode:Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged ' Dim dtgrdv1row As String ' Dim checkrowclick As String ' checkrowheaderclick = True ' ' If DataGridView1.Rows(0).Selected Then ' MsgBox("Colum header") ' Else disabletextfield() ' If DataGridView1.rowhe Then Button2.Enabled = False Button3.Enabled = True Button4.Enabled = True Button6.Enabled = True Button7.Enabled = True ' ' If DataGridView1.CurrentRow.Cells(0).Value <> vbNull Then nullreferenceEXCEPTION starts here when i click the column header ComboBox5.Text = DataGridView1.CurrentRow.Cells(0).Value 'Tripticket 'End If ComboBox1.Text = DataGridView1.CurrentRow.Cells(2).Value 'trucker ComboBox2.Text = DataGridView1.CurrentRow.Cells(3).Value 'plate number ComboBox3.Text = DataGridView1.CurrentRow.Cells(4).Value 'Truck Type TextBox7.Text = DataGridView1.CurrentRow.Cells(5).Value 'Driver TextBox3.Text = DataGridView1.CurrentRow.Cells(6).Value 'Destination TextBox6.Text = DataGridView1.CurrentRow.Cells(7).Value 'CustomerName TextBox1.Text = DataGridView1.CurrentRow.Cells(8).Value 'Load rmrkstxtbox.Text = DataGridView1.CurrentRow.Cells(9).Value 'remarks End Sub




Reply With Quote