Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27517

Problem with index after adding row with datagridview

$
0
0
I have a project written in Visual Studio 2008 (VB NET) using a data bound Datagridview control and BindingNavigator (w/ menustrip) control. If I select the Add New button on the Binding Navigator the Datagridview control moves to a new record with an index of -1 but does not add a record to the database.

When I add a record to the database via a query Me.TableAdapter.AddRow() the row is added to the database and the Datagridview control moves to a new record with an index of -1 but does not refresh with the new row.

Using the NewRow of the Datagridview produces worse results, so I have disabled allowing users to add new rows to the Datagridview.

With the following code

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click

Me.TableAdapter.AddData() 'inserts a new row
BindingSource.ResetBindings(True)

end sub

it works (adds a row to the database (SQL) and updates the datagridview which I can then modify. However, I still end up with a negative index for that row. Adding additional rows decreases my index (-2, -3, etc). Any ideas anyone?

:cry:

Viewing all articles
Browse latest Browse all 27517

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>