Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Listview-box connecting ;-seperated textfile

Listview-box connecting ;-seperated textfile

Listview-box connecting ;-seperated textfile


I would like to make a Listview-box. Has somebody the example sourcecode for it?

Then I would like to make a connection to a ';' seperated textfile, so that the contents of the textfile can fill the listview box made in ad.1

Thanks a lot,

David Reuvekamp
The Netherlands

RE: Listview-box connecting ;-seperated textfile

ad.1 -- See Thread101-112945 and www.bcbcaq.com for some examples.

ad.2 -- I'll post some code that I regularly use later today if someone else doesn't beat me to it.

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

RE: Listview-box connecting ;-seperated textfile

You are great!!

RE: Listview-box connecting ;-seperated textfile

    Here is how I frequently parse files with fields delimited by something like ";" or "|". It is by no means the only method nor may it be the best but it works for me so I use it a lot. Please note that while the code works for me, I do not know the particulars about your file so you will have to modify this code.

    Just for this example, let us assume that the text file you want to parse looks something like this:
I1; I2 ; i3
thing1; thing2;thing3
1; 2 ;3

    Notice that I don't make any assumptions about whether there are spaces before or after the ";". I do make an assumption that there are three fields on each line. This is only for the example.

    To start out with, you will need to include the file stream  and string stream libraries in your file. Include these libraries after the #pragma hdrstop. You code may look something like this:

#pragma hdrstop

// Add the following comments and code manually
// Standard C++ libraries
#include <fstream>
#include <sstream>

    Now you can start adding your parsing code. I don't know where you want to pick up your file. I usually pick up a file in the section where a button is "pressed." If my form (FORM1) has a bitbtn, I would put my code in the "click" method. So my code would go into void __fastcall Form1::BitBtn1Click(TObject *Sender)

    So here we go:

// First set up the file name to be parsed.
String FileName = "D:\\SomeDirectory\\SomeSubDirectory\\TheFile.txt";

// If you really want some error checking, do this
bool FileIsThereBool = FileExists(FileName);

if (!FileIsThereBool)
     // The file does not exist so do some sort of message
     Application->MessageBox("Could not find the file.", "File Error", MB_OK);
     // Exit the method

// Now open the file
ifstream ParseFile; // input file stream set up
ParseFile.open(FileName.c_str()); // c_str will put Ansistring to char string

// Can we process the file?
if (!ParseFile)
    // No! there was an error opening file
    Application->MessageBox("Could not process file.", "File Error", MB_OK);
    // Now we are going to get each line in the file before we parse it.
    // Start by setting up a C++ string to hold the file's line
    string ImpLine;

    // Now we get the line in the file up to the ending newline character
    // The while loop will get every line in the file
    while (getline(PostingFile, ImpLine, '\n'))
        // Now we will process the input string into parts via string stream
        // You could also use substrings but this is cleaner, IMHO

        // Get line from input string
        istringstream StrLine(ImpLine);

        // Now let's set up the parts of the file. You could do this through
        // a ListView, a vector, or like this example, through C++ string.
        string OnePart, TwoPart, ThreePart

        // The real work of parsing the line is done here
        // Notice that the last part must pick up the linefeed since there
        // isn't a ; after it

        // Now you can do what you want with the parts
        // For example, you could trim the spaces from the string
        // or you could convert them to numbers if possible.

    // Now close the file

    That's it. You will probably notice some errors that crept in as I translated this code from my "working" code to the example. Good luck! (You'll probably need it with my advice. )

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

RE: Listview-box connecting ;-seperated textfile

To James P. Cottingham,

Yhanks for your answer and the time you offered. It is for me a good start en now I will work with it.


David Reuvekamp
The Netherlands

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close