MFC Edit Control: How to replace a line in a multi-line edit control?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

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

  1. #1
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,051

    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.

    Code:
    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);
        m_edit.ReplaceSel(pszNewText);
      }
    }
    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center