none
focus issue RRS feed

  • Question

  • i have mdi application, on main form which is mdi container and has a tree view. i open the child form on afterselect even of treeview.

    the issue i'm facing that i open the form but focus remain on tree view until i click on the the form.

    my question is how i can give focus to form rather it stays on treeview

    i tried frm.focus also activatemdichild(frm)

    no sucess.

    thanks in advance,
    p
    Thursday, June 11, 2009 7:59 PM

Answers

  • oops..here

    Private Delegate Sub FocusSelector(ByVal node As TreeNode)

        Private Sub HandleClick(ByVal node As TreeNode)
         
            frm.txtID.focus()

        End Sub


    and in event did following

    Dim m As FocusSelector = New FocusSelector(AddressOf HandleClick)
     
            Me.BeginInvoke(m, e.Node)



    • Marked as answer by Parry2k Friday, June 12, 2009 12:17 AM
    Friday, June 12, 2009 12:01 AM

All replies

  • A form cannot get focus. You have to have one of the controls on the form get focus.

    If there is no control on the form that you want to have focus, the trick we gave to another poster about a week ago was to put a control off the viewable area of the form (negative x or y) and give it focus.

    Hope this helps.


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Thursday, June 11, 2009 9:19 PM
  • i have controls on the form but still focus remains on treeview
    Thursday, June 11, 2009 9:36 PM
  • here is my code on treeview_afterselect, i call a sub which is ShowForm()

    and sub is like this

    private sub showform()
    dim frm as new form
    dim n as integer

    try
      n = cint(me.treeview1.selectednode.tag)
     
     select case  n
     case 1
        frm = form1
     case 2
        frm = form2
     case 3
        frm = form3
    end select

    frm.mdiparent=me
    frm.show()

    end sub

    now it show the form but focus remains on treeview not on the form

    i give the focus on each formload event as well but still no success.

    any idea?
    Thursday, June 11, 2009 9:43 PM
  • nothing, i put the two text box on main form and try to give focus , doesn't work

    instead of following line

    frm.mdiparent=me
    frm.show()

    i did

    me.textbox1.focus

    or

    me.textbox1.select()

    but focus remain on the currently selected node in the gridview
    Thursday, June 11, 2009 9:51 PM
  • Not sure I understand where you are doing all of this.

    Form 1: TreeView.

    Form 2: TextBoxes?

    Both are MDI child forms?

    You open Form 2 from Form 1 and Form 2 does not get focus?

    Or does it get focus along with the TreeView? If the later, ensure you have the TreeView HideSelection property set to True.


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Thursday, June 11, 2009 9:56 PM
  • hi deborahk,

    let me explain it again

    i have 4 forms.  main is mdiform and have one treeview which has 3 nodes called form1,form2,form3

    now when a node is selected i want to open that form and want the focus to be on the 1st control of form.

    so on treeview1.activeselect event i called a procedure name showform()

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

            ShowForm()
      


        End Sub

    the showform is explained earlier, is it clear now?


    Thursday, June 11, 2009 10:04 PM
  • Is the new form at least on top? Or is it behind your TreeView form?

    What type of control should be getting the focus on Form1? Is it a TextBox? Or something else?

    (Just trying to narrow down the possibilities here.)


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Thursday, June 11, 2009 10:17 PM
  • yes it show the form, not behind the treeview. there are textbox on child form and want to give the focus to first textbox on form which txtID


    Thursday, June 11, 2009 10:20 PM
  • as i said earlier i put another textbox control on main form for testing and if i try to give focus to any of those control it will not work.


    Thursday, June 11, 2009 10:22 PM
  • i docked the treeview on left on main form and child form doesn't go behind treeview
    Thursday, June 11, 2009 10:56 PM
  • I *was* able to reproduce your problem doing this:

    1) Created an MDI parent form.

    2) Created a child form with a TreeView control.

    3) Added code to the MDI parent form to display the Treeview form.

    4) Created a child form with some TextBoxes.

    5) Upon click on a TreeView node, display the child form (passing in the MDI parent form, not "me") when bringing up the TextBox form from the TreeView form.


    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Thursday, June 11, 2009 11:02 PM
  • didn't get it

    why you have treeview on child form. treeview is on mdi parent form not on child,

    i'm just wondering if we both are on same page...
    Thursday, June 11, 2009 11:05 PM
  • Hi
    have you tried :

    My.Application.OpenForms("formname").Activate()
    Jerry
    Thursday, June 11, 2009 11:26 PM
  • it doesn't help either

    to debug further, i put this on tree view enter event

    msgbox(me.activecontrol.tostring()

    what i notice as soon as treeview after select event is fired, whatever you do in it, like give focus to another form control or whatever, the control comes back to treeview and enter event get fired.

    so basically after select event of treeview it fires the enter event

    Thursday, June 11, 2009 11:30 PM
  • i found following thread but it is in c#

    can someone convert it in vb.net for me

    i think we are almost there.... :)
    Thursday, June 11, 2009 11:38 PM
  • I've tried everything I can think of. It almost looks like a bug.

    The second child form (with the TextBoxes) comes up from the TreeView form and "looks" like it has focus (the title bar is selected, for example). If you check with the MDI parent, it thinks that child form (the TextBoxes form) is the active form. But if you press a key or touch the tab, you are still moving around in the first child form (TreeView form).

    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Thursday, June 11, 2009 11:52 PM
  • resolved

    i did following, converted code from another thread in vb.net

    here is the code
    Thursday, June 11, 2009 11:56 PM
  • I didn't see any provided code?
    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Thursday, June 11, 2009 11:57 PM
  • oops..here

    Private Delegate Sub FocusSelector(ByVal node As TreeNode)

        Private Sub HandleClick(ByVal node As TreeNode)
         
            frm.txtID.focus()

        End Sub


    and in event did following

    Dim m As FocusSelector = New FocusSelector(AddressOf HandleClick)
     
            Me.BeginInvoke(m, e.Node)



    • Marked as answer by Parry2k Friday, June 12, 2009 12:17 AM
    Friday, June 12, 2009 12:01 AM
  • That was what it was starting to look like ... like the TreeView AfterSelect was not actually done selecting so after it gave focus to the MDI child, the focus went back to the TreeView to finish the internal AfterSelect processing.

    So the BeginInvoke code will ensure that the Treeview internal code is done processing before processing your code in the event procedure.

    Glad you got this one fixed. Seems like I have been batting 0 on trying to assist you with your issues these past few days. :-)
    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Friday, June 12, 2009 12:08 AM
  • well thanks for your help and all the efforts.

    but i'm sure these look like tiny issues turn out complex and will help other people to use and make things easy for us.

    once again thanks everyone who participated in this thread.


    cheers and good luck.

    i have to mark my reply as an answer to close this thread :D :(
    Friday, June 12, 2009 12:17 AM