How to highlight a field when I click on it.
-
Sunday, March 11, 2012 6:56 PM
I'm not sure how to even ask for what I need. I have a form with many input fields. Here is what I want to do. When I click on a field I want the contents to highlight and then if any new data is entered it will overwrite the current contents. The way it is now, when I click on a field if there is any data in the field I must first use the delete key or the backspace key to get rid of the current data. If I just type the new data it just inserts it. For example, if the field has "Bob" in it and I want to replace it with "Jack" I have to delete the contents. If I start typeing I may end up with "BobJack", or "BoJackb" or "BJackob" or so on. I want to overwrite the existing data.
I hope I am clear in what I am wanting to do.
Thanks for any help.
- Edited by Philip Potts Sunday, March 11, 2012 6:58 PM
All Replies
-
Sunday, March 11, 2012 7:00 PM
Your "fields" are presumably textboxes, so all you need is something like this:
Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter Dim TB As TextBox = CType(sender, TextBox) TB.SelectAll() End Sub- Marked As Answer by Philip Potts Sunday, March 11, 2012 7:28 PM
-
Sunday, March 11, 2012 7:04 PMThank you Dave. Yes, the fields are testboxes and I have 30 of them. Do I need your code for each of them?
Philip
-
Sunday, March 11, 2012 7:14 PM
Hi Philip, I agree with Dave :)
No you don't need for each textbox this code, just add to the end of first line after 'Handles' keyword your controls:
Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter.... Dim TB As TextBox = CType(sender, TextBox) TB.SelectAll() End Sub
For now they are TextBox1, TextBox2, TextBox3... just add the other controls at the end
Regards Muli :)
If some code doesn't work, don't worry help is on the way.. don't forget to mark your thread as solved when done...
-
Sunday, March 11, 2012 7:29 PMThat did it. Thanks to both of you for your help.
Philip

