Cant set focus to textbox

Cant set focus to textbox

Post by Tosc » Fri, 22 Apr 2005 15:03:56


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
 
 
 

Cant set focus to textbox

Post by Joop » Fri, 22 Apr 2005 15:44:18

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

 
 
 

Cant set focus to textbox

Post by Tosc » Fri, 22 Apr 2005 16:31:03

Joop,
no the textbox is on the usercontrol. There is no textbox on the form,
just the usercontrol and two buttons.

Tosch
 
 
 

Cant set focus to textbox

Post by Cor Ligthe » Fri, 22 Apr 2005 16:44:54

Tosch,

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

I hope this helps,

Cor
 
 
 

Cant set focus to textbox

Post by Tosc » Fri, 22 Apr 2005 18:32:12

Yes, checked this several times.


On Thu, 21 Apr 2005 09:44:54 +0200, "Cor Ligthert"
 
 
 

Cant set focus to textbox

Post by Cor Ligthe » Fri, 22 Apr 2005 18:51:10

Tosch,

And how did you set them, for me it works that way.

Cor