Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Binding XamGrid to DataTable not working
posted

Hi,

I try to bind the XamGrid (not XamDataGrid) to DataTable but it doesn't work.

I can see the grid with the right columns butwhen I add rows to the DataTable they don't appear in the XamGrid.

I checked that the rows adding is in the Main thread, I don't understand what is missing.

The Xaml:

<ig:XamGrid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="dataGrid" AutoGenerateColumns="False" ItemsSource="{Binding Path=StatisticsView}" >

<ig:XamGrid.SortingSettings>

<ig:SortingSettings AllowSorting="False"/>

</ig:XamGrid.SortingSettings>

<ig:XamGrid.SelectionSettings>

<ig:SelectionSettings

CellClickAction="SelectCell"

CellSelection="Single"

RowSelection="None"/>

</ig:XamGrid.SelectionSettings>

<ig:XamGrid.EditingSettings>

<ig:EditingSettings

AllowEditing="None"/>

</ig:XamGrid.EditingSettings>

<ig:XamGrid.Columns>

<ig:TextColumn Key="Name" Width="*">

<ig:TextColumn.HeaderTemplate>

<DataTemplate>

<TextBlock Text="Name" FontSize="8"/>

</DataTemplate>

</ig:TextColumn.HeaderTemplate>

</ig:TextColumn>

<ig:TextColumn Key="Min" Width="40">

<ig:TextColumn.HeaderTemplate>

<DataTemplate>

<TextBlock Text="Min" FontSize="8"/>

</DataTemplate>

</ig:TextColumn.HeaderTemplate>

</ig:TextColumn>

<ig:TextColumn Key="Max" Width="40">

<ig:TextColumn.HeaderTemplate>

<DataTemplate>

<TextBlock Text="Max" FontSize="8"/>

</DataTemplate>

</ig:TextColumn.HeaderTemplate>

</ig:TextColumn>

<ig:TextColumn Key="Average" Width="40">

<ig:TextColumn.HeaderTemplate>

<DataTemplate>

<TextBlock Text="Avg" FontSize="8"/>

</DataTemplate>

</ig:TextColumn.HeaderTemplate>

</ig:TextColumn>

</ig:XamGrid.Columns>

</ig:XamGrid>

The ViewModel:

private DataTable statisticsTable;

statisticsTable = new DataTable("Statistics");

statisticsTable.Columns.Add("Name",typeof(string));

statisticsTable.Columns.Add("Min", typeof(string));

statisticsTable.Columns.Add("Max", typeof(string));

statisticsTable.Columns.Add("Average", typeof(string));

var newRow = statisticsTable.NewRow();

newRow["Name"] = channelName;

newRow["Min"] = min.ToString();

newRow["Max"] = max.ToString();

newRow["Average"] = avg.ToString();

statisticsTable.Rows.Add(newRow);