I have to List of Data :
List<string[]> dataRow = new List<string[]>();
- every string[] array are full with 30 data for each row.
- Column Name are already exists.
I'm trying to display it like this :
XAML :
<DataGrid Margin="8,259,8,8" IsReadOnly="True" AutoGenerateColumns="False" AlternatingRowBackground="Gainsboro" AlternationCount="2" Name="MyDataGrid" />
C# :
MyDataGrid.ItemsSource = dataRow;
foreach( string[] cellContent in dataRow )
{
foreach( string text in cellContent )
{
var column = new DataGridTextColumn
{
Binding = new Binding(text)
};
MyDataGrid.Columns.Add(column);
}
}
but i got a "ContextSwitchDeadlock" Error. How can i solve this?
Thank u for Helping
EDIT : solved but not with the databinding Way
I solved it like this :
List<string> ColumnName = new List<string>();
List<string[]> dataRow = new List<string[]>();
DataTable myTable = new DataTable();
// Fill Array ColumnName and dataRow Here
foreach (string text in ColumnName)
{
myTable.Columns.Add(text);
}
foreach (string[] cellContent in dataRow)
{
myTable.Rows.Add(cellContent);
}
DatensatzGrid.ItemsSource = myTable.AsDataView();
Thank u for all the reply!!
MyDataGrid.ItemsSource = MyDataGrid