I trying to bind a few arrays into a Wpf datagrid using C#. What i able to do is only bind one array into the datagrid. Does anyone know how to bind more than one array into a datagrid? The code i try below doesn’t work. The datagrid show nothing.
My Datagrid code snippet:
<DataGrid Name="MyDatagrid" Grid.Column="1" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Date" Width="60" Binding="{Binding Date}"/>
<DataGridTextColumn Header="Time" Width="55" Binding="{Binding Time}"/>
<DataGridTextColumn Header="No" Width="69" Binding="{Binding No}"/>
</DataGrid.Columns>
</DataGrid>
C# code snippet:
string[] Date = {"2-Nov-2012","2-Nov-2012","2-Nov-2012","2-Nov-2012","2-Nov-2012"};
string[] Time={"10:30","10:32","10:35","10:42","10:45"};
int[] No = { 1, 2, 3, 4, 5 };
MyDataGrid.ItemsSource = No;
MyDataGrid.ItemsSource = Date;
MyDataGrid.ItemSource = Time;
You can’t bind multiple arrays to the same Data Grid; but you can achieve the same end with a class:
Populate using Linq: