?
Solved

Select all text when mouse click in an Edit Box

Posted on 2010-09-22
4
Medium Priority
?
659 Views
Last Modified: 2013-12-14
Is there a way in C++ to select all data in a control (TEdit), when the OnEnter event fires?  If the user TAB's into the field all data is automatically selected, but if they click in the field the | cursor is simply inserted where they clicked, I would like to have the OnEnter select all text in the control, so the mouse click works as the TAB does.

I have already tried (to no avail):
FieldName->SelStart =0;
FieldName->SelLength = FieldName->Text.Length();

I also tried the following 2 variations:
SendMessage(FieldName->Handle, EM_SETSEL, 0, -1);                  
SendMessage(FieldName->Handle, EM_SETSEL, 0, FieldName->Text.Length());                  

I use C++Builder v6 if that matters
0
Comment
Question by:BarrieAtTheBeach
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 2000 total points
ID: 33737099
It seems that even if you call the onenter event when you click into the tedit the internal onclick is fired for last (so the cursor position is changed).
Have you tried writing your code into the OnMouseDown event instead?
0
 

Author Comment

by:BarrieAtTheBeach
ID: 33737183
I have not attempted to use any OnMouse event, but will explore that avenue and post back.
0
 

Author Comment

by:BarrieAtTheBeach
ID: 33737457
Thank you Ferruccio68. Your suggestion led to the solution I will employ.

On Enter
//Set a global variable that field has been entered
  bGlobalFeildEntered = true;

On Exit
  bGlobalFeildEntered = false;

On Mouse Down
if (bGlobalFeildEntered)
{
  bGlobalFeildEntered = false;
  SendMessage(FieldName->Handle, EM_SETSEL, 0, -1);
}
0
 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 33743729
Glad to have helped you.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question