Solved

Select all text when mouse click in an Edit Box

Posted on 2010-09-22
4
653 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
Comment Utility
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
Comment Utility
I have not attempted to use any OnMouse event, but will explore that avenue and post back.
0
 

Author Comment

by:BarrieAtTheBeach
Comment Utility
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
Comment Utility
Glad to have helped you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now