Solved

Programmatically highlight text in CEdit

Posted on 2001-06-18
5
571 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
notReplace  challenge 53 116
Hibernate methods 2 68
sum28 challenge 31 106
zeroMAx challenge 20 87
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

920 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

12 Experts available now in Live!

Get 1:1 Help Now