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">
<TextBlock Text="Min" FontSize="8"/>
<ig:TextColumn Key="Max" Width="40">
<TextBlock Text="Max" FontSize="8"/>
<ig:TextColumn Key="Average" Width="40">
<TextBlock Text="Avg" FontSize="8"/>
</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);
Hello Dudi,
I’ve created a simple example that simulates adding a new row and displaying it in the xamGrid control.
Hope this example will be helpful.
The example is not useful, I think the OnDataObjectRequested event is called when adding new row to the grid. I add row to the DataTable and want to see it in the grid.
Anyway, I used the OnDataObjectRequested and it didn't help.
You may find the following example useful. It demonstrates how to implement adding a new row when the xamGrid control ItemsSource is DataTable. You should handle the OnDataObjectRequested event.
http://ko.infragistics.com/samples/wpf/grid/binding-to-data-table
Forgot to mention:
public DataView StatisticsView
{
get { return statisticsTable.DefaultView; }
}