Answer the question
In order to leave comments, you need to log in
Ordinal number in GridView when displaying information from text?
Hello.
I display the data from the file in the dataGridView in the following way:
string[] arr = System.IO.File.ReadAllLines(filename, Encoding.Default);
for (int i = 0; i < arr.Length; i++)
{
// вывод
dataGridView1.Rows.Add(arr[i].Split(" ".ToCharArray()));
}
Answer the question
In order to leave comments, you need to log in
Pushing data from a file directly into the grid is not the best way to work.
It is best to make an intermediate model, and at least the line class in which you will have an Id - just the line number, well, in addition to Id, you can make one - two string variables into which you will fill in data from the file.
Or, if there can be more than two of them, then I would declare line to be the heir of some kind of list and add words to it, another thing is that it is much more difficult to display such crap.
And the conclusion to the grid of this is simple. After reading the file, you will have some kind of List, and you simply write:
datagridview.ItemSources = myListOfLines;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question