Datagrids...help read textfile?

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
I need to write a program that can read a textfile, and sort the information in the text into a datagrid. I'm fine with the reading and sorting of the text, but I'm having trouble with the datagrid. I've never used a datagrid before and do not know where to begin. I can't even seem to find a way to add coloumns or rows, let alone add my text. Can someone help me with this?
 
wha's the format of the text in the file?

for datagrids i find it best to build a dataset (which means using a datatable and datacolumns) then simply bind the datagrid to the new dataset

i can help with this, but first we need to establish what the data format is
 
I don't exactly know what you mean by format, but I'll give you some more information. For privacy reasons I can't give you the actual text, but I'll show you how it is organized. This is the information it has

Rank(short), Lastname(String), Firstname(String), School(String),Score(Short). (The period shows the end of this entry, the start of next one)

I don't exactly know how a datagrid works, but I was going to create a loop which would add the information to an array. I would probably create a class to store all the information for one entry, then continue looping and adding another class to the array. Then the information would be easy to access.

Hopefully I've given you enough information, in the meantime I'll continue trying to sort this out.
 
I wrote a class recently that uses regular expressions to translate textual information on the fly, into another form.


I use it for directly reading fixed-width files into a dataset. All you need to do is set up the correct regular expressions and you'll be able to read your file straight into a datatable too...

Usage is something like:

Dim rfrmr as New RegexFindReplaceMutatingReader
rfrmr.AddFindReplacePair(..., ...)

Dim ds a New DataSet
ds.ReadXml(rfrmr);


All you need to work out is the regex to transform your info into a datatable.

Other options you ahve are writing a schema.ini and using the Jet database driver to SELECT * FROM your_text_file; same ends, different means
 
A list of terms I don't understand from the previous post:regex, shema.ini, jet database, etc.

Basically, the entire thing was over my head.Thanks for the help, but I've got to walk before I can run. I don't even know exactly what a dataset is. I assume you can somehow load an arraylist into a data set.Can I load a dataset into a datagrid? If so, how would it appear, as a coloumn, row or the entire grid?

Your rfrmr sounds like a good solution to my problem. Could you explain it in greater detail?
 
regex: regular expression, a sophistacted text-pattern-matching device
jet: database technology that is designed to read and write what normal computer users call "Microsoft Access Databases". Access is a front end to Jet
schema.ini: jet's driver is pretty good. if you write a schema.ini file that tells it how to treat a text file, then you can select from that text file as though it were a database table
dataset: a collection of datatables. datasets do not contain data. you cant "add an arraylist to a dataset" because datasets themselves contain no data. you can create a bunch of datarow from an arraylist, and those datarows can be added to a datatable which can be added to a dataset..
datagrid: a display component intended for visualising a block of data stored in a datatable. datagrids dont contain data, they simply show the contents of any object that implements IBindingList, of which a datatable is just such an example
rfrmr: a class I wrote that performs find/replace operations on a stream of text as it is read in..

the idea being you attach the rfrmr to a text file and then tell a dataset to read from an rfrmr. Whatever format the text file is in, it is the rfrmr's job to find and replace on that data so that it becomes usable to the ReadXml method of a dataset.

Read XML is a simple chappie: it expects data in a nice xml layout something like:
VB.NET:
<dataset name>
  <datatable name>
    <column name>value</column name>
    ...
    <column name>value</column name>
  </datatable name>
</dataset name>

All you must do is code the find and replace routines in rfrmr to do this replacement. Because regex are very sophisticated (though the lingo looks a bit weird, its almost a language within its own right), this is usually quite easy!
 
Back
Top