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!

Update startup datagrid form from 2nd form

Status
Not open for further replies.

custsoft

Programmer
Aug 29, 2000
41
I have a startup form that allows a person to select an existing record from a datagrid. After you select a record to change, the second form displays the details of the selected record in a text box format. Once the update button is selected on the second form I want to update that record in the datagrid on the first form. In the second form I dimension the first form as "Public frmFirstForm As New frmFirstForm" which allows me to enter the following code on exit from the second form:
frmFirstForm.lblOwnerSelect.Text = "this is it"
frmFirstForm.DstCemeteryOwner1.Clear()
frmFirstForm.oledb_adapCemetery.Fill(frmFirstForm.DstFirstForm)
The problem is when I close the second form nothing is changed on the first form. If I do a frmFirstForm.showDialog() I see the first form with the updated data but the first form with the old data is still displayed. If I don't do the showDialog nothing changes. I would appreciate any help anyone could be with this. Thanks in advance.
 
In the second form I dimension the first form as "Public frmFirstForm As New frmFirstForm"

> Do you see the first form ?? Yes. This means that somewhere there was a dim statement to init a new firstform... That form (first, with the datagrid) is inited and displayed as soon as you click RUN form visual studio. By writing the above bold line, you just init a new one. So there are two forms with the datagrid. The new has the updated data and the old is the same.

How to fix: You need to add a main sub in the program and start from there: I think:

dim tf as firstFormName
Application.Run(New tf)

Then use your code (3 lines), but not the bold

There are other ways also, to get the data from the popup from (using .showdialog) back to the first form and update the grid
 
Thank you very much, I understand what you are saying but I am new to VB.NET. How do you add a sub main to the program? Do you know, without spending much time on it, how the solution would include the .showdialog ? Thank you very much, again. It must be gratifying to be able to help someone that is up against a wall.
 
Add a module and write in it:

Code:
Module Module1
    Public s As New Form1

    Sub main()
        Application.Run(s)
    End Sub
End Module

From the project properties set the startup object to be the sub main

Use from an other form :
s.datagrid1. blah blah

As a beginner, you will not be able to use properties, .. so reference the controls directly, like shown above
 
That worked. Thanks TipGiver. I am not sure why it didn't work when I did "Public Form1 as New Form1" but that did not work. You have to use a different name. Thanks again.
 
Form1 is a readonly ID. Cannot be used as a variable.
Instead of Public Form1 as New Form1
USe Public something_else as New Form1

The something_else cannot be Form1 (conflict). It cannot be also any other keyword like "on", "while", "dataset" and so on.

(This could be handled with namespaces..)

Anyway, use:
Public myForm1 as New Form1
 
Sorry, but this is getting more complicated. What is the difference between application.run(something_else) vs something_else.showDailog(). It appears that my initial startup screen which was called Form1 now has to reference everything as something_else????
 
Sorry again, I was wrong about references in my first form being messed up. It appears as long as I use me. it seems to be OK.
 
OMG I posted an answer to you but lost. This problem has occured some times.
Just for the admins to see: It loads a page having as response >. or .>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top