Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, January 11, 2014 3:04 PM
Good day!!!
I have a ProductsDataGridView , after i press the Save button , i have to close and reopen the application in order to view the new record added.
Is there a code or something that i can put in the btnSave_click event to view my new product without restarting the application ?
All replies (4)
Saturday, January 11, 2014 8:55 PM ✅Answered
hi alluka,
try this :
datagridview1.refresh()
If you use data-bound controls, the code looks like:
bindingSource1.DataSource = testTableAdapter.GetData()
bindingSource1.ResetBindings(false)
or
datagridview1.DataSource = dataset
or
datagridview1.DataSource = datatable
for more info, see below link:
http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx
best regards.
Saturday, January 11, 2014 9:32 PM ✅Answered
Hello,
If the method to access and modidy (including add new rows) was setup via using the IDE data wizard you should not have to close and re-open the application to view the new row. The new row shows and if the primary key is a visible column the value for the primary key would show up as a negative number unless you have written and executed a secondary SQL statement (SELECT @@IDENTITY) in RowUpdated event to get the new key for the new row then set the new records primary key to that value.
Example
Private Sub parentAdapter_RowUpdated(sender As Object, e As OleDbRowUpdatedEventArgs)
'We are only interested in new records.
If e.StatementType = StatementType.Insert Then
'Get the last ID auto-generated by the database.
Dim lastAutoNumber = Me.parentAdapter.GetLastAutoNumber().Value
'Update the ID of the local row.
DirectCast(e.Row, ParentChildDataSet.ParentRow).ParentID = lastAutoNumber
End If
End Sub
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Saturday, January 11, 2014 10:48 PM
Thank you it all work
Saturday, January 18, 2014 7:16 AM
Thanks for the help...it works