CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Posts
    115

    Exclamation Problem on setfocus

    Hi everybody,

    I have a project which contains two forms.

    One form contains a combobox and a datagridview control

    2nd form contains a textbox and a command button and several Radio Buttons.

    When I run the programme the 1st Form is loaded and it is displaying with a combobox and datagridview
    If I select somethings from combobox the system showing 2nd form with three type ofcontols(textbox,command
    button,radio buttons etc) on top of form No one.

    Now I am selecting some radio buttos and clicking command button for execution some job then the 2nd form is closed and
    1st form's datagrid view displaying some records and set focus goes to combobox not in gridview. as result
    I can't do anything on gridview.

    although I have written setfocus on gridview but still the focus goes to combo box
    why setfocus is going to combo box instead of gridview.

    Please suggest me how to setfocus on to gridview after clicking command button of 2nd form.

    //Code
    commandbutton_click

    1stForm.Datagridview.focused()

    //Code

    Thanking you

    Debasis

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Problem on setfocus

    Maybe something else wrong, because this works perfectly :

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim frm2 As New Form2
            frm2.Show()
            frm2.DataGridView1.Focus()
        End Sub

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Problem on setfocus

    //Code
    commandbutton_click

    1stForm.Datagridview.focused()

    //Code
    The Focused() statement checks to see if the object has focus.
    To set the focus to an object you use

    Code:
    Object.Focus
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Problem on setfocus

    Quote Originally Posted by DataMiser View Post
    The Focused() statement checks to see if the object has focus.
    To set the focus to an object you use

    Code:
    Object.Focus
    Good eyes!

    Guess I didn't see it properly as Debasis Bag didn't put the the code in [CODE] tags, which has been asked a million times already.

    Debasis, please, use [CODE] tags; it is explained here :

    http://www.codeguru.com/forum/showthread.php?t=403073

    It is really not difficult, and really not too much to ask of you...

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

Featured