By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

Cant set focus to textbox

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

"Tosch" <to**********@swissonline.ch> wrote in message
news:c8********************************@4ax.com...
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

Nov 21 '05 #2

P: n/a
Joop,
no the textbox is on the usercontrol. There is no textbox on the form,
just the usercontrol and two buttons.

Tosch

On Thu, 21 Apr 2005 11:14:18 +0430, "Joop" <ip*@nt.co> wrote:
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

"Tosch" <to**********@swissonline.ch> wrote in message
news:c8********************************@4ax.com.. .
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


Nov 21 '05 #3

P: n/a
Tosch,

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

I hope this helps,

Cor
Nov 21 '05 #4

P: n/a
Yes, checked this several times.
On Thu, 21 Apr 2005 09:44:54 +0200, "Cor Ligthert"
<no************@planet.nl> wrote:
Tosch,

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

I hope this helps,

Cor


Nov 21 '05 #5

P: n/a
Tosch,

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

Cor
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.