display data of text file in list view
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Thread: display data of text file in list view

Threaded View

  1. #11
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Iasi - Romania

    Re: display data of text file in list view

    [ continued ]

    Step 2: Read from text file and fill CDemoDocument::m_arrLines.
    One common place to load the document is the overridden CDocument::Serialize.
    However, this is not the best place in our case. We can get a CFile*pointer from CArchive argument or the file name. First is no use, because we need CStdioFile* (derived from CFile*). Also, we cannot use the file name because further we canget a share violation.
    So better let's override CDocument::OnOpenDocument and simply call _ReadTextFile, similar to the method from that FAQ mentioned earlier.
    class CDemoDocument : public CDocument
       // ...
       // Attributes
       CStringArray m_arrLines;
       // Operations
       CStringArray& GetDocumentData() {return m_arrLines;}
       // ...
       // ...
    // Overrides
       virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
    // Implementation
       void _ReadTextFile(LPCTSTR pszFileName, CStringArray& arrLines);
    BOOL CDemoDocument::OnOpenDocument(LPCTSTR lpszPathName)
       if (!CDocument::OnOpenDocument(lpszPathName))
          return FALSE;
       _ReadTextFile(lpszPathName, m_arrLines);
       return TRUE;
    void CDemoDocument::_ReadTextFile(LPCTSTR pszFileName, CStringArray& arrLines)
       CString strLine; 
          CStdioFile file(pszFileName, CFile::modeRead); 
          e->ReportError(); // shows what's going wrong 
    [ to be continued ]
    Last edited by ovidiucucu; September 25th, 2012 at 02:45 AM. Reason: typos
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    My likes on StumbleUpon
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

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.com survey!

HTML5 Development Center