Click to See Complete Forum and Search --> : selecting text in edit control programmatically


April 1st, 1999, 02:19 PM
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

April 1st, 1999, 03:37 PM
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-

April 1st, 1999, 04:16 PM
CEdit * ce = (CEdit *)GetDlgItem(IDC_ED1);
ce->SetFocus();
ce->SetSel(0,5,FALSE);
Deep

Roller8
April 1st, 1999, 05:28 PM
This worked perfectly! Thank you for your help.