I am having some problems when I have a datatable and I want to bind each datagridtextcolumn in the datagrid to each column in the datatable.
my code is as below
public class Packet
{
public Header header { get; set; }
public Frame frame { get; set; }
public Tail tail { get; set; }
public String id { get; set; }
public Packet(String id,Header header, Frame frame, Tail tail)
{
this.id = id;
this.header = header;
this.frame = frame;
this.tail = tail;
}
}
Hence on my xaml side
<Grid >
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=.}" Name="dgrid" SelectionChanged="dgrid_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding Path=id}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
And on my code side, ds is a dataset which has one datatable. Each row is a packet 4 columns corresponding to header frame tail and id. I am trying to get the id to bind correctly first. But the id number cannot display on the datagrid.
dgrid.DataContext = ds.Tables[0];
It actually displays the correct data if i do not use the datagridtextcolumn on the xaml side. but what i wanted is to do the binding on the xaml side to the datatable.
ds.Tables[0]was initialized correctly? - Jin-Wook Chung