DatagridView issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Tressle

    #1

    DatagridView issue

    I've just started learning vb.net and although it's awesome I've been
    tearing my hair out trying to find a solution to this specific problem. I
    have a form with 2 data grid views and I would like the 2nd datagrid view to
    automatically be populated with relevant data when the selected row is
    changed on the first datagridview.

    I have created the dataset and 2 table adapters (the 2nd expecting a
    parameter for the SQL Select statement). On the first datagrid I have the
    following code:

    Private Sub DGV1_SelectionC hanged(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles DGV1.SelectionC hanged
    If Not IsDBNull(DGV1.C urrentRow.Cells (3).Value) Then
    Me.Table2TableA dapter.Fill(Me. myDataSet.Table 2,
    DGV1.CurrentRow .Cells(0).Value )
    End If
    End Sub

    This is working fine - until I try and reorder DGV1 by clicking on the
    column headers... then I get a NullreferenceEx ception - Object reference not
    set to an instance of an object. Help!!! I haven't got much hair left to
    pull out!

    Thanks,
    John

  • Cor Ligthert [MVP]

    #2
    Re: DatagridView issue

    John,

    Use the datatable.defau ltview on your first grid for the datasource, with
    that the information stays after a sort.

    Cor

    "John Tressle" <john.tressle@n ospam.comschree f in bericht
    news:kjBNh.2144 23$1E3.103601@f e3.news.blueyon der.co.uk...
    I've just started learning vb.net and although it's awesome I've been
    tearing my hair out trying to find a solution to this specific problem. I
    have a form with 2 data grid views and I would like the 2nd datagrid view
    to
    automatically be populated with relevant data when the selected row is
    changed on the first datagridview.
    >
    I have created the dataset and 2 table adapters (the 2nd expecting a
    parameter for the SQL Select statement). On the first datagrid I have the
    following code:
    >
    Private Sub DGV1_SelectionC hanged(ByVal sender As System.Object, ByVal e
    As
    System.EventArg s) Handles DGV1.SelectionC hanged
    If Not IsDBNull(DGV1.C urrentRow.Cells (3).Value) Then
    Me.Table2TableA dapter.Fill(Me. myDataSet.Table 2,
    DGV1.CurrentRow .Cells(0).Value )
    End If
    End Sub
    >
    This is working fine - until I try and reorder DGV1 by clicking on the
    column headers... then I get a NullreferenceEx ception - Object reference
    not
    set to an instance of an object. Help!!! I haven't got much hair left to
    pull out!
    >
    Thanks,
    John

    Comment

    • =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=

      #3
      RE: DatagridView issue

      John,

      You are trying to reference DGV1.CurrentRow .Cells property when you may not
      have a current row - hence your NullReferenceEx ception

      HTH

      "John Tressle" wrote:
      I've just started learning vb.net and although it's awesome I've been
      tearing my hair out trying to find a solution to this specific problem. I
      have a form with 2 data grid views and I would like the 2nd datagrid view to
      automatically be populated with relevant data when the selected row is
      changed on the first datagridview.
      >
      I have created the dataset and 2 table adapters (the 2nd expecting a
      parameter for the SQL Select statement). On the first datagrid I have the
      following code:
      >
      Private Sub DGV1_SelectionC hanged(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles DGV1.SelectionC hanged
      If Not IsDBNull(DGV1.C urrentRow.Cells (3).Value) Then
      Me.Table2TableA dapter.Fill(Me. myDataSet.Table 2,
      DGV1.CurrentRow .Cells(0).Value )
      End If
      End Sub
      >
      This is working fine - until I try and reorder DGV1 by clicking on the
      column headers... then I get a NullreferenceEx ception - Object reference not
      set to an instance of an object. Help!!! I haven't got much hair left to
      pull out!
      >
      Thanks,
      John
      >
      >

      Comment

      Working...