Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Programmatically highlight text in CEdit

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 35
deburging in oracle form 12 104
Change owner from userA to server Local Administrators 7 66
"Black Box" Testing of Control System Software 2 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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