Solved

Select all text when mouse click in an Edit Box

Posted on 2010-09-22
4
658 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 22

Accepted Solution

by:
Ferruccio Accalai earned 500 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 22

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

724 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