Solved

Programmatically highlight text in CEdit

Posted on 2001-06-18
5
570 Views
Last Modified: 2013-11-20
This should be easy.  I've got a Edit Box in a dialog. In OnInitialUpdate(), I set the text of the edit box, and I would like it to to appear selected initally.

m_strText = "Test";
UpdateData(FALSE);
m_edit.SetSel(0, -1);

The text shows up, but is not highlighted.
Any ideas?

Thanks,
Marcus
0
Comment
Question by:marcus78
  • 3
5 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 6205014
your CEdit may not be focused when you are trying to set the selection
0
 
LVL 22

Expert Comment

by:ambience
ID: 6205016
do you see no highlight whereas the carets inside the box ?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 6205229
>>Edit Box in a dialog. In OnInitialUpdate(), I set the text ...

Do you mean in OnInitDialog() ??  If so, there is a bit of a quirk that could be in play here -- you will see one result in NT/2K and one in Win9x.  The simplest solution is to make the Edit box the first itme in the dialog (first in the tab order -- ask and I'll explaine)

Next, have you ever noticed that the ClassWizard may put some text like:

 return TRUE;  // return TRUE  unless you set the focus to a control


So, try this in OnInitDialog():
1) Set Focus to the Edit control -- use cMyEdit.SetFocus()
2) Set the selection -- as you hav shown
3) return FALSE

let me know what happnes.

-- Dan


0
 

Author Comment

by:marcus78
ID: 6207469
Dan - Thanks!  That was it, and yes I did mean OnInitDialog().  Thanks for the catch.

Marcus
0
 
LVL 22

Expert Comment

by:ambience
ID: 6209046
good shot Dan ! thats four the moment it left the bat :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

16 Experts available now in Live!

Get 1:1 Help Now