I am using Visual Studion 2015, .NET Framework 4.5.2, working with WPF, and want to assign the content of an imported CSV-file in a simple way to a DataGrid object, which is described here:
<Grid>
(...)
<DataGrid Name="dgOutput"
CanUserAddRows="True"
CanUserResizeColumns="True"
CanUserSortColumns="True"
Margin="24,142,112,109"
Grid.ColumnSpan="2"
Grid.RowSpan="2"
IsReadOnly="True">
</DataGrid>
</Grid>
I am using the following method:
public MainWindow()
{
InitializeComponent();
string[] raw_text = System.IO.File.ReadAllLines("c:\\temp\\import.csv");
string[] data_col = null;
int x = 0;
foreach (string text_line in raw_text)
{
data_col = text_line.Split(',');
if (x == 0)
{
for(int i =0; i <= data_col.Count() -1; i++)
{
dgOutput.Columns.Add(data_col[i]);
}
}
else
{
}
}
}
However I get an error as following:
CS1503
cannot convert from 'string' to 'System.Windows.Controls.DataGridColumn'
How to get rid of this problem?