Solved

Select all text when mouse click in an Edit Box

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

773 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