-
September 24th, 2012, 04:35 AM
#1
display data of text file in list view
i want to display data from text file in list view and in tree view root will be file name, but i dont know how to do it, the problem is with displaying text file data in list view, i don't know anything about that.
text file data is very simple
it is just a square matrix of double values like:
21.06 34.06 5.0
12.78 45.25 6.9
12.89 45.98 5.5
in list view i want to display it.
-
September 24th, 2012, 04:59 AM
#2
Re: display data of text file in list view
Have a look at the MFC CListCtrl class
Victor Nijegorodov
-
September 24th, 2012, 05:21 AM
#3
Re: display data of text file in list view
First, have a look at CStdioFile Class and/or at How to read a text file line by line?.
Next, to parse each particular line, use CString::Tokenize.
Finally, fill the listview control, using CListCtrl methods, as Victor already suggested.
Last edited by ovidiucucu; September 24th, 2012 at 05:25 AM.
-
September 24th, 2012, 05:32 AM
#4
Re: display data of text file in list view
these are the things i can just read and understand im totally new at this can smone plz give me step by step guide and some sample code, i know how to create list view and adding items and columns but i dont know how to do it with file i have done reading file line by line using other method at some other place for storing values in matrix but i dont know reading here for list view, can smone help me with sample code for the example i quoted in first post
-
September 24th, 2012, 05:38 AM
#5
Re: display data of text file in list view
Well, why don't you ask for the entire program then? Ovidiu already provided links to examples, so why don't you start by looking at them and give them a try. You shouldn't expect others to do your work. Instead you should try harder by yourself.
-
September 24th, 2012, 06:02 AM
#6
Re: display data of text file in list view
Even advanced programmers can be "totally new" in some circumstances until reading and understanding the documentation. That's programmer's life, often you have to sweat a little instead of asking others to do all the work for you, for free.
Just giving some more hints:
- If using MFC, to fill a listview, have a look at CListCtrl::InsertColumn, CListCtrl::InsertItem, and CListCtrl::SetItem / CListCtrl::SetItemText.
- If not using MFC but plain WinAPI, have a look at LVM_INSERTCOLUMN, LVM_INSERTITEM, and LVM_SETITEM / LVM_SETITEMTEXT.
- For documetation details and examples, have a search in MSDN Library.
- Also you can have a look in Codeguru's ListView Control Articles.
After that, if something isn't yet clear and/or doesn't work as expected, show us what you have tried to do, then we can help you with more details and advices.
Last edited by ovidiucucu; September 24th, 2012 at 06:32 AM.
-
September 24th, 2012, 06:41 AM
#7
Re: display data of text file in list view
And here is a quick example, filling a listview control by using MFC:
Code:
const int nColCount = 10;
const int nRowCount = 100;
CString strText;
// add listview columns
for(int nCol = 0; nCol < nColCount; nCol++)
{
strText.Format(_T("Column %d"), nCol);
m_listCtrl.InsertColumn(nCol, strText, LVCFMT_LEFT, 100, nCol);
}
// add and set listview items
for(int nItem = 0; nItem < nRowCount; nItem++)
{
m_listCtrl.InsertItem(nItem, NULL);
for(int nSubItem = 0; nSubItem < nColCount; nSubItem++)
{
strText.Format(_T("Item (%02d, %02d)"), nItem, nSubItem);
m_listCtrl.SetItemText(nItem, nSubItem, strText);
}
}
Of course, you can notice that's not exactly for copy-paste purpose.
It's to just to show "HOW TO", like many other examples you can find over the internet, in manuals, documentation, tutorials, and so on.
Next, you have to sweat a little and adapt it to your specific requirements/needs.
Last edited by ovidiucucu; September 24th, 2012 at 06:45 AM.
-
September 24th, 2012, 09:42 AM
#8
Re: display data of text file in list view
i dont have any problem with creating right view, thanx for your help but i already know that, what im asking is about reading file and tokenizing and then getting access to that read data for displaying. my questions
i have tried reading file and have made ReadTextFile(...) member function of listview class
Q1. is this function called automatically somewhere or i have to call it explicitly
Q2. if i have to call it explicitly somewhere im confused ,how to provide its parameters i.e LPCTSTR pszFileName, CStringArray& arrLines from where did i get them
Q3. tokenize is used to parse string so first i have to get string from arrlines right?arrLines.Add(strLine); is used to add string ,which function is better to be used for getting string from arrlines?
pardon me for asking basics but im quite new to visual c++ thats why.
Last edited by tspga; September 24th, 2012 at 09:55 AM.
-
September 24th, 2012, 09:50 AM
#9
Re: display data of text file in list view
Originally Posted by tspga
i dont have any problem with creating right view, thanx for your help but i already know that, what im asking is about reading file and tokenizing and then getting access to that read data for displaying. my questions
i have tried reading file and have made ReadTextFile(...) member function of listview class
Q1. is this function called automatically somewhere or i have to call it explicitly
Q2. if i have to call it explicitly somewhere im confused ,how to provide its parameters i.e LPCTSTR pszFileName, CStringArray& arrLines from where did i get them
Q3. tokenize is used to parse string so first i have to get string from arrlines right? which function is better to be used for that purpose?
pardon me for asking basics but im quite new to visual c++ thats why.
1) You would have to call it explicitly. Why would you think otherwise?
2) You know the name of the file, not us. I don't really see why you need a CStringArray at all, but it could be a member of your view class.
3) ovidiucucu gave you links in post #3.
-
September 24th, 2012, 01:34 PM
#10
Re: display data of text file in list view
i have to get the file name from open file dialog so i must call this function in either openfile or open document and then pass it on to this read function
and question 3 was asked after viewing those links i have viewed but you have not Q3 was about the things not mention in that link
-
September 24th, 2012, 02:00 PM
#11
Re: display data of text file in list view
Is your application SDI, MDI or dialog-based?
Is your class which keeps the listview control derived from CListView or CListCtrl?
Last edited by ovidiucucu; September 24th, 2012 at 02:02 PM.
-
September 24th, 2012, 02:13 PM
#12
Re: display data of text file in list view
CString str( arr.GetData() ); i tried this and getting errors like
CString(const class CString &)' : cannot convert parameter 1 from 'class CString *' to 'const class CString &' when i try this
CAtlString str( arr.GetData() ); it says
error C2065: 'CAtlString' : undeclared identifier
E:\MyProjects\my interface\CExerciseDoc.cpp(93) : error C2146: syntax error : missing ';' before identifier 'str'
E:\MyProjects\my interface\CExerciseDoc.cpp(93) : error C2065: 'str' : undeclared identifier
when i include header #include "cstringt.h" it says header file not found.
-
September 24th, 2012, 02:26 PM
#13
Re: display data of text file in list view
yes it is SDI and windows explorer based, and has dialogs from menu
class CRightView : public CListView
yes this is the case.
-
September 24th, 2012, 02:27 PM
#14
Re: display data of text file in list view
yes it is SDI and windows explorer based, and has dialogs from menu
class CRightView : public CListView
yes this is the case.
-
September 25th, 2012, 02:11 AM
#15
Re: display data of text file in list view
Originally Posted by tspga
CString str( arr.GetData() ); i tried this and getting errors [...]
This is wrong, and I just can guess your intention is to extract an element from an array (CStringArray).
For doing that, you have to use CStringArray methods GetAt, ElementAt, or operator [].
Originally Posted by tspga
yes it is SDI and windows explorer based, and has dialogs from menu
class CRightView : public CListView
yes this is the case.
You should give such information from the beginning. Now, it's pretty clear what you want to accomplish.
Let's try to solve it, step by step!
Presume we have CDemoDocument and CDemoListView, derived from CDocument and CListView, respectively.
First, in document-view architecture it's good to keep data in the document class (the class derived from CDocument). To avoid a bi-dimensional array, I would like to suggest an array of strings, each element being a line read from a text file.
So, step 1: add a CStringArray member to CDemoDocument and a public method to retrieve in the CDemoListView class.
Code:
class CDemoDocument : public CDocument
{
// ...
// Attributes
private:
CStringArray m_arrLines;
// Operations
public:
CStringArray& GetDocumentData() {return m_arrLines;}
// ...
};
[ to be continued ]
Last edited by ovidiucucu; September 25th, 2012 at 02:45 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|