Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting Focus On A Control

Posted on 2009-07-07
2
Medium Priority
?
225 Views
Last Modified: 2013-12-26
I have a form with a tabcontrol.  Within the 3rd tabpage of the 1st tabcontrol is another tabcontrol.  On the 1st tabpage of the 2nd tabcontrol is a set of controls (datagridview, combobox, textbox, etc.).  When I click on the 3rd tabpage of the 1st tabcontrol the "_Enter" event for the 3rd tabpage of the 1st tabcontrol is fired and the datagridview is loaded.  Right after that I want to set the focus to the combobox that is also on that tabpage.  The combobox.focus does not seem to work.  Solution?

Private Sub tbpgTransactions_Enter(ByVal sender As Object, ByVal e As _ 
& System.EventArgs) Handles tbpgTransactions.Enter
        SqlDataAdapter1.SelectCommand.CommandText = "SELECT * FROM HM_Transactions"
        SqlDataAdapter1.Fill(HmsDataSet1.HM_Transactions)
        cbMntTrnAccountNumber.SelectedIndex = 27
        cbMntTrnAccountNumber.Focus()
    End Sub

Open in new window

0
Comment
Question by:StoneCutter3
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24799146
Handle SelectedIndexChanged() event of the TabControl itself.

In the example below I'm using TabControl2:
    Private Sub TabControl2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl2.SelectedIndexChanged
        If TabControl2.SelectedTab Is tbpgTransactions Then
            ...
            cbMntTrnAccountNumber.Focus()
        End If
    End Sub

Open in new window

0
 

Author Closing Comment

by:StoneCutter3
ID: 31600768
Nice.  Thanks alot.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question