Textfile beim Einlesen Zerstückeln?

M

Michael Schindler

Ich habe es nun erreicht, ein textfile einzulesen das nun zeile für zeile im
datagrid angezeigt wird.

Nun wäre es toll wenn ich das textfile zum beispiel nach jedem blank in eine
spalte zerstückeln könnte und meine frage hier wie geht sowas?

Ich habe nun das ganze mit folgendem code im datagrid, nur zu welchem
zeitpunkt zerstückle ich das und meine eigentliche frage wie kann ich das
dann in die jeweiligen spalten stellen?

Beispiel meines textfile:
-----------------------
123 Auto BMW 45000
777 Auto Audi 88000

Schön wäre es wenn ich nun 4 spalten und 2 zeilen hätte. Momentan bringe ich
es auf eine spalte und 2 zeilen.
myDataView.Sort = "Spalte1";

ds.Tables.Add(MyTable);


dataGrid1.DataSource = MyTable;

Wäre toll um eine kleine hilfe von Euch



Danke Gruess



Michael
 
E

Eric Johannsen

Hi Michael,

Your chances of getting help increase exponentially if you use english -
just because so many more people will understand what you are asking for.
Don't worry if your english isn't perfect, or even broken... many people
reading the news group are not native speakers.

I think this is what you are looking for:

private void Form1_Load(object sender, System.EventArgs e)
{
string delimiters = " ";
string textLine = "This is my text";
DataTable dt = new DataTable("myTable");
dt.Columns.Add("First");
dt.Columns.Add("Second");
dt.Columns.Add("Third");
dt.Columns.Add("Fourth");
dt.Rows.Add(textLine.Split(delimiters.ToCharArray()));
dataGrid1.DataSource = dt;
}

The code assumes you have created a data grid called dataGrid1 on a form
called Form1.

Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top