Newbie: Trigger event on form's *complete* visibility

S

steve

Hi,
I have the following very annoying problem:

Form1 gets user's choices to construct an SQL string and when Button Extract
gets hit a new form, Form2, is supposed to open with the results of the
querry.

Now, I overloaded the New() of Form2 so that i can pass the SQL string
generated by Form1 to Form2.

Sub New(ByVal SQLstring As String)
InitializeComponent( )
rtbSQL.Text = SQLstring ' <-- This just puts the SQL string as text in a
textbox of FORM2 for visual inspection
End Sub

Then, I create the DataSet etc... to fill up a datagrid with the results.
This is done by calling FillGrid( ) from
Form2's Load( ) event.

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
'While (Not Me.Visible)
'End While

'Delay - 1 sec

' Fill the Scenario DataGrid
FillGrid()
End Sub

Very Simple!! and straightforward.

HOWEVER! the follwoing happens: Depending on how long it takes from the
server to respond and fill the DataGrid, I see an hourglass and ...I wait.
I want to SHOW first Form2, with the textbox filled, and THEN call
FillGrid( ). It's more visually pleasing.

But no matter what i try, nothing works. (look at the commented-out While
loop above), Delays, etc..

If insted of Form2_Load( ), I use Form2_Activated ( ) , I "begin to see
the borders of the form, but its still the same idea, same delay. I do not
see the form completely unless the Datagrid is Filled.

Any suggestions would be greately appreciated.
 
G

Guest

Steve,

Does doing a Me.Show followed by a Me.Refresh as the first two lines of code
in the form's load event help?

Kerry Moorman
 
S

steve

Well, just a "ghost" of the outline of the form, but not a "real" solid form
with the textbox filled.

Very smart idea though! I played around a bit with it, moving the statements
in different places to no avail!...
I also combined it with my delays, etc as in my original message.
 
A

Armin Zingler

steve said:
Well, just a "ghost" of the outline of the form, but not a "real"
solid form with the textbox filled.

Very smart idea though! I played around a bit with it, moving the
statements in different places to no avail!...
I also combined it with my delays, etc as in my original message.

Have you also tried calling me.refresh within the form's activated event?

Private Sub Form1_Activated( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Activated

Static done As Boolean
If Not done Then
done = True
Me.Refresh()
'execute query here
End If
End Sub


Armin
 
S

steve

It works!!!!
Thanx a million!

*But*, i remember in my previous attempts using the Activated method, and it
seemed to do some weird things. How does Activated gets triggered? By
clicking on form? by passing the mouse ? If the form gets activated multiple
times, don't we loose a lot of resources ? unless that's the price to pay.

I added the following to your code:

Static counter As Integer = 0
Static done As Boolean = False

If Not done Then
done = True
Me.Refresh()
FillScenarioGrid()
End If

counter += 1
MsgBox(counter.ToString)

and the msgbox keeps popping up with updated values of the counter.
So, is this an expensive but necessary solution?

Thanx for any comments and your time !

-steve
 
S

Steve

Hi Steve

You could try doing an application.doevents just before your DB access,
which allows the pending form-painting events to be processed. I ended up
settling with this solution after trying various combinations of
refresh/show/update calls.

Steve2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top