Hello everybody,
I have many textboxes in my form
In the lostfocus event of every textbox I store its name in a string variable called LastUsedTextBox
I also have many other controls on my form
I have a button
If the focus is on any other control which is not textbox then I want to have focus on textbox whose name was previously stored in the LastUsedTextbox (String) by clicking on the button
Does any one knows the answer.
Thanks in advance.
8 Replies - 197 Views - Last Post: 23 January 2013 - 02:59 PM
#1
Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:04 PM
Replies To: Focus on a textbox whose name is stored in a variable in vb.net
#2
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:16 PM
You mean something like:
Where LastTextUsed might hold the string value "TextBox1"
Me.Controls(LastTextUsed).Focus()
Where LastTextUsed might hold the string value "TextBox1"
This post has been edited by CharlieMay: 23 January 2013 - 01:16 PM
#3
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:20 PM
Loop through the list of MyForm.Controls
Find the one with that name
Set the focus to it.
But if it were me trying to force the user to walk through those textboxes, I would use the .Enabled property.
Start with all the controls set to .Enabled = false
Then you can enable as they properly complete one box. When all is good, you can enable the [SUBMIT] button or whatever you have. That primitive animation of the control changing gets the user attention so they realize what they should do next.
Find the one with that name
Set the focus to it.
But if it were me trying to force the user to walk through those textboxes, I would use the .Enabled property.
Start with all the controls set to .Enabled = false
Then you can enable as they properly complete one box. When all is good, you can enable the [SUBMIT] button or whatever you have. That primitive animation of the control changing gets the user attention so they realize what they should do next.
#4
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:26 PM
Yes Exactly that
#5
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:28 PM
This is unclear to me. At what point do you want the focus to suddenly move from one control to another?
If it is when the form is first opened (within your application) then you can set the focus to the last-used textbox, but you would need to store the name of this last-control in My.Settings.
Edited: Sorry, the previous posts have made it a little clearer. Ignore me
If it is when the form is first opened (within your application) then you can set the focus to the last-used textbox, but you would need to store the name of this last-control in My.Settings.
Edited: Sorry, the previous posts have made it a little clearer. Ignore me
This post has been edited by andrewsw: 23 January 2013 - 01:34 PM
#6
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:30 PM
this can be done in the windows forms but if i want to write this line a class library or a custom control project then what should I write?
I tried this but I failed
mybase.controls(LastUsedTextBox).Focus()
Any other solutions
I tried this but I failed
mybase.controls(LastUsedTextBox).Focus()
Any other solutions
#7
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:36 PM
andrewsw, on 24 January 2013 - 01:58 AM, said:
This is unclear to me. At what point do you want the focus to suddenly move from one control to another?
If it is when the form is first opened (within your application) then you can set the focus to the last-used textbox, but you would need to store the name of this last-control in My.Settings.
If you want to do this as the user switches between different forms, then most uses would find this a very annoying feature.
Perhaps you should clarify.
If it is when the form is first opened (within your application) then you can set the focus to the last-used textbox, but you would need to store the name of this last-control in My.Settings.
If you want to do this as the user switches between different forms, then most uses would find this a very annoying feature.
Perhaps you should clarify.
This question was an example to simplify the problem
Currently I am working on a custom control which is inheritated from textbox and have a property called AssociatedDataGridView
So I am searching in AssociatedDataGridView what user writes in the textbox
But I got a problem here
I want if the user clicks on the AssociatedDataGridView the focus should be returned to the textbox
because this Textbox and DatagridView should work like a single control
#8
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 01:39 PM
Quote
Loop through the list of MyForm.Controls
Find the one with that name
Set the focus to it.
Find the one with that name
Set the focus to it.
Shouldn't need to loop(?):
Me.Controls(LastUsed).Focus()
#9
Re: Focus on a textbox whose name is stored in a variable in vb.net
Posted 23 January 2013 - 02:59 PM
no
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|