The easiest way is to import the text file into a DataTable and then bind the DataTable to the DataGridView using the DataSource property.
The file looks like a fixed or limited data file. There are many libraries that would help to read such files in a DataTable, for example, this one on codeproject.com comes to mind.
Here's how you do it with the GenericParser described above:
// DataFilePath stores the path + file name of your data file. using (var p = new GenericParsing.GenericParserAdapter(DataFilePath)) { // Assumes your data file is fixed width, with the column widths given in the array. p.ColumnWidths = new int[] { 8, 12, 9, 9, 5, 11 }; p.FirstRowHasHeader = true; DataTable dt = p.GetDataTable(); dataGridView1.DataSource = dt; }
Please note that you need to add GenericParsing.dll as a link in your project.
source share