Solved

Programmatically highlight text in CEdit

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

17 Experts available now in Live!

Get 1:1 Help Now