This is a continuation of a question that I asked previously
Bind jagged string array to a DataGrid
In my code, I am importing rows from a CSV and storing them in a jagged array. I also ask the user if the first row contains column headers. If it does, then I use that row as the column name. What I can't figure out though is how do I exclude the first row of the array from the DataGrid
ItemSource
. Here is the method so you can see exactly what I am doing.
private void Import_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult headerChoice = MessageBox.Show("Is the first row a column header?", "Import Options", MessageBoxButton.YesNo);
string[][] array = fs.CSVToStringArray();
string[] headerTitles = new string[array[0].Length];
for (int i = 0; i < array[0].Length; i++)
{
var col = new DataGridTextColumn();
if (headerChoice == MessageBoxResult.Yes)
col.Header = array[0][i];
else if (headerChoice == MessageBoxResult.No)
col.Header = "Column " + i;
col.Binding = new Binding(string.Format("[{0}]", i));
this.ExternalData._dataGrid.Columns.Add(col);
}
if (headerChoice == MessageBoxResult.Yes)
//exclude first row of array;
else if (headerChoice == MessageBoxResult.No)
this.ExternalData._dataGrid.ItemsSource = array;
}
Where I have the comment "exclude first row of array" I want to put some code that binds the array to the ItemSource
and excludes the first row, because it is a column header.