• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

Programmatically highlight text in CEdit

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
marcus78
Asked:
marcus78
  • 3
1 Solution
 
ambienceCommented:
your CEdit may not be focused when you are trying to set the selection
0
 
ambienceCommented:
do you see no highlight whereas the carets inside the box ?
0
 
DanRollinsCommented:
>>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
 
marcus78Author Commented:
Dan - Thanks!  That was it, and yes I did mean OnInitDialog().  Thanks for the catch.

Marcus
0
 
ambienceCommented:
good shot Dan ! thats four the moment it left the bat :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now