Results 1 to 3 of 3

Thread: [RESOLVED] Datagridview.Selectionchanged event

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    6

    Resolved [RESOLVED] Datagridview.Selectionchanged event

    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..

    Code:
     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
    thanks for helping out

  2. #2
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: Datagridview.Selectionchanged event

    Set the sortmode to unsortable. This will stop the column headers from being clicked.

    Computerman
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    6

    Re: Datagridview.Selectionchanged event

    yah i tried that.. and it works thanks

    now the problem is sorting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width