How to select all text every first focus?
H
I am looking for this default routine, i need all text in the textbox will be selected every time the textbox is clicked / instead of clicking and ctrl + A
How can this be achieved? (If focused, skip this)
SIGN IN To post a reply.
8 Replies
1 reply marked as answer
VR
Vijayalakshmi Roopkumar
Syncfusion Team
October 15, 2020 10:26 AM UTC
Hi Khanh,
Thank you for contacting Syncfusion Support.
Query: i need all text in the textbox will be selected every time the textbox is clicked / instead of clicking and ctrl + Alt. How can this be achieved? (If focused, skip this)
From your update, we could understand that you want to select all text on clicking the textbox and you want to deselect the text, if the textbox get focused. If this your requirement, then you can achieve using SelectAll method on click event of TextBoxExt and we have unselected the text using the following code:
Code:
|
// Select all text at click event
private void TextBoxExt1_Click(object sender, EventArgs e)
{
this.textBoxExt1.SelectAll();
}
|
|
//unselect the text on focus
private void TextBoxExt1_GotFocus(object sender, EventArgs e)
{
this.textBoxExt1.Select(this.textBoxExt1.Text.Length, 0);
}
|
Sample: https://www.syncfusion.com/downloads/support/forum/158705/ze/TextBoxExt_selectall-2082780302
Please try this solution and let us know if it is helpful.
Regards,
Vijayalakshmi VR
TG
The GridLock
October 15, 2020 02:47 PM UTC
Hi Vijayalakshmi,
I'm working with a multi-line textbox,
Your code works partly for me,
i'm looking for the following codes:
if (textbox.focus) return; // if focusing then nothing happens
textbox.selectall; // happens for each first focus
Your code works with every click, I want after the first click, it has to ignore because it's focused, but it's still selectall.
BR
Backia Raj Kanagaraj
Syncfusion Team
October 16, 2020 12:54 PM UTC
Hi Khanh,
We have checked your reported issue with our source and its reproduce at our end. We have forward this to our development team. We will update the further details on 20th October 2020.
Regards,
Backia Raj Kanagaraj
BR
Backia Raj Kanagaraj
Syncfusion Team
October 20, 2020 12:18 PM UTC
Hi Khanh,
Thanks for your patience.
We have checked your query “Need to ingnore the focus after the first click”. You can achieve this by unhook the click event of TextBoxExt control. Please refer the below code snippet and sample below,
Code Example
|
this.textBoxExt1.GotFocus += TextBoxExt1_GotFocus;
this.textBoxExt1.Click += TextBoxExt1_Click;
private void TextBoxExt1_Click(object sender, EventArgs e)
{
this.textBoxExt1.SelectAll();
this.textBoxExt1.Click -= TextBoxExt1_Click;
}
private void TextBoxExt1_GotFocus(object sender, EventArgs e)
{
this.textBoxExt1.Select(this.textBoxExt1.Text.Length, 0);
}
|
Sample link: https://www.syncfusion.com/downloads/support/forum/158705/ze/TextBoxExt_sample-367205950
Please let us know if you have any concerns.
Regards,
Backia Raj Kanagaraj
Marked as answer
TG
The GridLock
October 20, 2020 07:50 PM UTC
Hi Backia Raj ,
based on your code, now they are working,
Is there a function that checks whether the textbox focusing in addition to using events, and a global variable for this?
BR
Backia Raj Kanagaraj
Syncfusion Team
October 21, 2020 10:37 AM UTC
Hi Khanh,
Thanks for your update.
You can achieve your requirement “Need to ingnore the focus after the first click” by using global variables. We have set bool variable is false after the first click. So that after the first click the text is not selected. Please refer the below code example and sample.
Code snippet:
|
private void TextBoxExt1_GotFocus(object sender, EventArgs e)
{
focused = true;
}
bool focused = false;
private void TextBoxExt1_Click(object sender, EventArgs e)
{
if (focused)
{
this.textBoxExt1.SelectAll();
focused = false;
}
} |
Please let us know if you have any concerns.
Regards,
Backia Raj Kanagaraj
TG
The GridLock
October 28, 2020 07:02 AM UTC
Hi Backia Raj.
it worked! my problem resolved!
VR
Vijayalakshmi Roopkumar
Syncfusion Team
October 29, 2020 04:54 AM UTC
Hi Khanh
Thank you for your update.
We are gald that our solution meets your requirement.
Please let us know if you need any further assistance.
Regards,
Vijayalakshmi VR
Thank you for your update.
We are gald that our solution meets your requirement.
Please let us know if you need any further assistance.
Regards,
Vijayalakshmi VR
SIGN IN To post a reply.
- 8 Replies
- 3 Participants
- Marked answer
-
TG The GridLock
- Oct 14, 2020 11:28 AM UTC
- Oct 29, 2020 04:54 AM UTC