Results 1 to 4 of 4

Thread: Form gotfocus trigger?

  1. #1

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228

    Unhappy Form gotfocus trigger?

    Hey everybody...just started porting all our programs to VB.NET and love the language but miss some of the straightforward ways of doing things in good old VB6.

    Here is the situation (oversimplified but you get my point).

    I have one main form with a command button
    Clicking the command button fires the code to bring up a clients purchase order.

    VB Code:
    1. Dim frm As New frmShowPurchaseOrder()
    2.         frm.WindowState = FormWindowState.Normal
    3.         frm.Show()

    This form has a button that, when clicked, fires the code to bring up a listing of products.

    VB Code:
    1. Dim frm As New frmShowProducts()
    2.         frm.WindowState = FormWindowState.Normal
    3.         frm.Show()

    The user then selects a product and hits submit. The product is added to the purchase order (through sql server SP's), and the form is closed.

    The problem lies in that i don't know how to set focus back to the PurchaseOrder form in order to tell itto refresh the datagrid that holds all products.
    At this point i am using

    VB Code:
    1. Private Sub frmShowPurchaseOrder_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    2.  
    3.         If g_intFormMaterialActivate >= 1 Then
    4.         Else
    5.             MsgBox("I am activated")
    6.             UpdateMaterialDataGrid()
    7.          'so they only fire it once
    8.             g_intFormMaterialActivate += 1
    9.         End If
    10.  
    11.     End Sub

    To fire the UpdateProductDataGrid() function call but it means that the user has to move the mouse and i want it to happen automatically.

    How can i do this once the form has focus?
    Sorry this has been so longwinded but i hate questions that are asked with too little detail.
    (although this may stretch the bounds ).

    Thanks in advance!!
    Soylent Green tastes like chicken

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I dunno if this would help you but you can try giving the form focus when after closing the previous form like this :

    In the closing event :
    VB Code:
    1. Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2. Form1.Focus()
    3. End Sub

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Instead of using the Show() method, use the ShowDialog(me) method.

    This will make the code stop executing at the ShowDialog call on the first form, and when that form is closed, you can then do what you need.

    Example.

    Dim frm As New frmShowPurchaseOrder()
    frm.WindowState = FormWindowState.Normal
    frm.ShowDialog(Me)
    'Execution stops until frm is closed.
    'Do processing here when frm is closed.




    Dim frm As New frmShowProducts()
    frm.WindowState = FormWindowState.Normal
    frm.ShowDialog(Me)
    'Execution stops until frm is closed.
    'Do processing here that has to be done when that form is closed.

  4. #4

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    NICE!!
    Hellswraith, if i am ever coming down to Utah I owe you a couple of beers! Been trying to figure out how to do this for a week now.
    Figured there had to be a way to do it.
    You chopped about 250 lines of code out of my program.

    Thanks again
    Soylent Green tastes like chicken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width