CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2003
    Iasi - Romania

    MFC Edit Control: How to replace a line in a multi-line edit control?

    Q: How to replace a line in a multi-line edit control?

    A: The example below shows how it can be done and to avoid often made mistakes.

    void CMyDialog::ReplaceEditLineText(int nLine, LPCTSTR pszNewText)
      // 'CEdit::LineIndex()' takes as parameter the index of the line
      // and returns the character index of the line specified. 
      // The character index is is the number of characters from 
      // the beginning of the edit control to the specified line.
      const int nLineStart = m_edit.LineIndex(nLine);
      if(nLineStart != -1)
        // 'CEdit::LineLength()' takes as parameter the character index
        // of the line and not the line index as often is mistaken.
        const int nLineLength = m_edit.LineLength(nLineStart);
        // select the line, and replace the text.
        m_edit.SetSel(nLineStart, nLineStart + nLineLength);
    Last edited by Andreas Masur; August 23rd, 2005 at 07:27 AM.

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)