Cant set focus to textbox

  • Thread starter Thread starter Tosch
  • Start date Start date
T

Tosch

I have a usercontrol with a label, a textbox, a treeview, a grid and a
couple of checkboxes.
The usercontrol is hosted on a form together with a cancel and a
accept button. This form is used to search records in a database.

On several forms in my application I show (modal) this form to search
records. Everytime I show the form I want the focus to be on the
textbox on the usercontrol.
This works the first time I display the form. But every other time I
just can't get the textbox to receive the focus.
I have tried everything.
I have setup a timer that goes off and tries to set the focus to the
textbox. The textbox.Focus returns false. I have checked the
..Activecontrol property and it tells me the textbox has the focus.
When I press TAB and then ShiftTab the focus is on the textbox. So
before pressing Tab it must have been on the textbox.
But no cursor is displayed and I can't enter any text.

Does anyone have an idea to force the focus to the textbox?

Tosch
 
I didn't get it clearly... if the textBox is on the modal from then it is
very easy to set the focus to its textBox when the modal form is shown.
I used this:

' In the calling form:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim f As New SplashForm
f.ShowDialog()
End Sub

' In the Splash or search from which you set as a dialog from:

Private Sub SplashForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.TextBox1.Focus()
End Sub

' Be sure to close the dialog form everytime the work with it finishes.
Correct me if i was wrong
 
Joop,
no the textbox is on the usercontrol. There is no textbox on the form,
just the usercontrol and two buttons.

Tosch
 
Tosch,

Did you everwhere set your tabindexes right.
(usercontrol and form)

I hope this helps,

Cor
 
Back
Top