Looking for the best way to get a dataset row column representing the current row.

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Hi Everyone,

Can you tell me the best way to get a dataset row and column for the currently highlighted row in a datagrid?

Using this code works ok as long as the user does not insert or delete from the dataset but editing is ok.

VB.NET:
        ' This parent ID is the key column for the Parents table.
        '--------------------------------------------------------
        With LightGridParentNames
            intParentID = objDataSetParentNames.Tables("Parents").Rows(.CurrentRow.Index).Item("ID")
        End With

If the user inserts, or deletes a row from the dataset then executes this code then the error shown in the attachment is displayed. Also when inserting, or deleting the value representing the ID number does not match what was in the dataview before the insert, or delete where the highlight bar is resting.

Could you tell me the best way to avoid the error?

Thanks.

Truly,
Emad
 

Attachments

  • error.jpg
    error.jpg
    540.2 KB · Views: 24
Here are 2 more attachments showing what happens before the error.

This is when the user inserts then clicks on the dataview which should display the correct details. It shows the wrong details being shown.

If the user does an edit, no error or problems exist.
 

Attachments

  • before clicking on Test 6 after inserting it.jpg
    before clicking on Test 6 after inserting it.jpg
    611.3 KB · Views: 25
  • after clicking on Test 6 before error but shows wrong details data.jpg
    after clicking on Test 6 before error but shows wrong details data.jpg
    613.1 KB · Views: 23
You should be using a BindingSource, so just ask it for it's .Current property, which returns a DataRowView. The .Row property gives the row:

Dim ro as MyTypedRow = DirectCast(DirectCast(myBindingSource.Current, DataRowView), MyTypedRow)


I normally make this a property of my form whenever I'm making a form that refers to current rows in grids
 
Back
Top