Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid refresh problem 1

Status
Not open for further replies.

miikel

ISP
Jul 28, 2004
21
GB
hello there.
I have a problem with a datagrid on a VB.net 2003 form.
the datagrid displays data from an mdb file via an odbc connection.
on the form i have a toolbar, some buttons and the datagrid.
on of hte buttons is an "Add New" option, that opens a new form to update data in the database.
all of this works as anticipated. however, this is where i run into difficulty.
i am simply unable to get the datagrid to refresh and show the new contents of the database. its probably something really straightforward that i am missing, but i just cannot seem to get it to happen.


code that calls the new form - this is in the toolbar1_buttonclick event.

<code>
Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 0
Dim addNew As Form = New AddNew
addNew.Show()

Case 1 : MsgBox("Delete")
End Select
</code>

this whole function is executed before the form is displayed on the screen, so any update commands i add here are running before the new items have been added.

i am unable to find an event that fires on the original form when the addnew form has completed.

i have tried to create a new instance of the original form in addnew and running a sub that would do the update, but it is not referencing the correct (original) version of the form.

Please could anyone help (that is, if you can understand my babblings :p)

thanks in advance
 
A data entry form based on another form's logic is a good candidate for a modal form.

If you change the following code
Code:
Dim addNew As Form = New AddNew
addNew.Show()

to

Code:
Dim addNew As Form = New AddNew
addNew.ShowDialog()
addNew.Dispose()
'**********Code to refresh DataSet here

then your execution on your first form will stop at the ShowDialog. It will resume after your AddNew form is closed.


 
lol i love it when a plan comes together!!
thank you so much!
i had a feeling there had to be a way to do it, but was kinda hoping i hadnt missed something THIS basic!!

thanks for taking the time to respond and refraining from throwing insults at this stupid noob!! :)
 
No problem. Just remember that this changes the behavior of your program. With your original code, someone could decide to add a new record, open up the AddNew form, and still work with the original form. In this case, once they open up the AddNew form, they won't be able to work with the original form until they close AddNew. However, this is usually the desired result, so it should work for you.
 
Yep, that is how it i want it to be.

thanks again.
starred for your efforts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top