CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    selecting text in edit control programmatically

    Hello all. I'm a definite newbie so please bear with me. I have a CRecordview with edit controls on it. The edit controls are bound to CString data variables in a database. I would like to be able to highlight the text in the edit control automatically, saving the user from having to use the mouse between every lookup. I tried using the SetSel() function in the EN_SETFOCUS message but I get an error stating that it is not a member of CString. I also tried using CWnd's GetDlgItem(IDC_ITEMNUMBER) but there doesn't seem to be a CWnd function for accomplishing this task. Any assistance is greatly appreciated. Thanks in advance.

    Roller8


  2. #2
    Guest

    Re: From Masaaki Onishi

    Hi.

    You had better cast GetDlgItem by CEdit*.
    CEdit* ptrEdit = (CEdit*)GetDlgItem(IDC_ITEMNUMBER);

    Or, use class wizard and make a control the member control.
    m_ctlEdit.SetSel(0,-1);
    Don't forget that this only works if the editbox has a focus.

    Hope for help.
    -Masaaki Onishi-




  3. #3
    Guest

    Re: From Masaaki Onishi

    CEdit * ce = (CEdit *)GetDlgItem(IDC_ED1);
    ce->SetFocus();
    ce->SetSel(0,5,FALSE);
    Deep


  4. #4
    Join Date
    Apr 1999
    Posts
    4

    Re: From Masaaki Onishi

    This worked perfectly! Thank you for your help.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured