Importing ascii file into DataGrid in C# WPF
I just started programming in C# and using WPF so pardon my ignorance. I'm creating an WPF application where I need to dynamically make a grid. The grid headers will be different every time based on information in the text file and I will only need this grid if the user opens it.
So right now, I'm able to brows for a file and get the path. Then after I create a datagrid, like this:
//Create a new data grid
DataGrid datagrid1 = new DataGrid();
Master.Children.Add(datagrid1);
Grid.SetRow(datagrid1, 1);
Grid.SetColumn(datagrid1, 1);
Now, I have issues accessing the file and populating the grid. How would I be able to do this in C#?
The file will first have this header:
Time x y speed_x speed_y acc_x acc_y Target Leg Type The header can have more paramaters depending on the file.then it will have an unknown开发者_运维百科 amount of row of data like this:
0.00 47.50 -42.50 -1.00 0.00 0.00 0.00 1 1 Sensor_1Is the file tab-delimited? If so, you will want to use the classes in the System.Data.OleDb namespace to get DataTable instances which you can easily bind to the grid.
精彩评论