Click here to Skip to main content
15,915,747 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm going to add string at runtime in edit control,I've tried with different method and strategies but it won't inserted or if inserted but not displayed in edit control!!!
How to make this!please give me solution.
Thanks in advance!!
Posted
Comments
Richard MacCutchan 14-Dec-12 5:18am    
You need to give more details of what you are doing and what results you see. We cannot guess what your code does.
Venkat Raghvan 14-Dec-12 5:24am    
I have one edit control & one button,whenever user press a button then String(which I declared at compile time)should be inserted in that edit control at runtime

1 solution

Inserting is performed by setting the position with SetSel() passing the position index as start and end point and replacing the (empty) selection with the text calling ReplaceSel(). To append text, pass -1 as position index. To set the complete text (replace all), use SetWindowText().

C++
// Insert text at specified position using a CEdit derived class
void CMyEdit::InsertText(int nPos, LPCTSTR lpszText)
{
    SetSel(nPos, nPos);
    ReplaceSel(lpszText);
}

// Insert text at specified position of a CEdit control that is a member of a dialog
void CMyDialog::InsertEditText(int nPos, LPCTSTR lpszText)
{
    m_edit.SetSel(nPos, nPos);
    m_edit.ReplaceSel(lpszText);
}

// Insert text at specified position of a CEdit inside a dialog using the resource ID
void CMyDialog::InsertText(int nID, int nPos, LPCTSTR lpszText)
{
    CEdit *pEdit = (CEdit *)GetDlgItem(nID);
    pEdit->SetSel(nPos, nPos);
    pEdit->ReplaceSel(lpszText);
}
 
Share this answer
 
Comments
Venkat Raghvan 14-Dec-12 9:19am    
Thanks for your reply,it will help me again!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900