I am trying to add rows to a xamgrid, this code will add the rows. However, when I try to Submit the changes to the datacontext, the data context does not recognize that I have added rows, so it will not submit the changes to the database. It will locally add rows, just not save them. Any thoughts? //datagrid.cs public NotesView() { InitializeComponent(); this.Loaded += new RoutedEventHandler(UserControl_Loaded); } void UserControl_Loaded(object sender, RoutedEventArgs e) { this.myXamGrid.ItemsSource= new ObservableCollection<EntityObject>(EntityObjectCollection); } //datagrid.xaml <igGrid:XamGrid x:Name="myXamGrid" AutoGenerateColumns="False" ColumnWidth="*" VerticalAlignment="Top" RowHover="Row" > <igGrid:XamGrid.CellStyle> <Style TargetType="igGrid:CellControl"> <Setter Property="FontSize" Value="10"></Setter> </Style> </igGrid:XamGrid.CellStyle> <igGrid:XamGrid.SelectionSettings > <igGrid:SelectionSettings CellClickAction="SelectRow" RowSelection="Single"/> </igGrid:XamGrid.SelectionSettings> <igGrid:XamGrid.EditingSettings> <igGrid:EditingSettings AllowEditing="Row" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsMouseActionEditingEnabled="DoubleClick" IsOnCellActiveEditingEnabled="True"/> </igGrid:XamGrid.EditingSettings> <igGrid:XamGrid.AddNewRowSettings> <igGrid:AddNewRowSettings AllowAddNewRow="Top" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsMouseActionEditingEnabled="SingleClick" IsOnCellActiveEditingEnabled="True"/> </igGrid:XamGrid.AddNewRowSettings> <igGrid:XamGrid.RowSelectorSettings> <igGrid:RowSelectorSettings Visibility="Visible" EnableRowNumbering="False"/> </igGrid:XamGrid.RowSelectorSettings> <igGrid:XamGrid.ColumnMovingSettings> <igGrid:ColumnMovingSettings AllowColumnMoving="Disabled"/> </igGrid:XamGrid.ColumnMovingSettings> <igGrid:XamGrid.Columns> <igGrid:DateColumn Key="DateEntered" HeaderText="Date Entered"/> <igGrid:TextColumn Key="Entry" TextWrapping="Wrap" Width="*"/> </igGrid:XamGrid.Columns> </igGrid:XamGrid>
I am trying to add rows to a xamgrid, this code will add the rows. However, when I try to Submit the changes
to the datacontext, the data context does not recognize that I have added rows, so it will not submit the changes to the database.
It will locally add rows, just not save them. Any thoughts?
//datagrid.cs
public NotesView() { InitializeComponent(); this.Loaded += new RoutedEventHandler(UserControl_Loaded); } void UserControl_Loaded(object sender, RoutedEventArgs e) { this.myXamGrid.ItemsSource= new ObservableCollection<EntityObject>(EntityObjectCollection); }
//datagrid.xaml
<igGrid:XamGrid x:Name="myXamGrid" AutoGenerateColumns="False" ColumnWidth="*" VerticalAlignment="Top" RowHover="Row" > <igGrid:XamGrid.CellStyle> <Style TargetType="igGrid:CellControl"> <Setter Property="FontSize" Value="10"></Setter> </Style> </igGrid:XamGrid.CellStyle> <igGrid:XamGrid.SelectionSettings > <igGrid:SelectionSettings CellClickAction="SelectRow" RowSelection="Single"/> </igGrid:XamGrid.SelectionSettings> <igGrid:XamGrid.EditingSettings> <igGrid:EditingSettings AllowEditing="Row" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsMouseActionEditingEnabled="DoubleClick" IsOnCellActiveEditingEnabled="True"/> </igGrid:XamGrid.EditingSettings> <igGrid:XamGrid.AddNewRowSettings> <igGrid:AddNewRowSettings AllowAddNewRow="Top" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsMouseActionEditingEnabled="SingleClick" IsOnCellActiveEditingEnabled="True"/> </igGrid:XamGrid.AddNewRowSettings> <igGrid:XamGrid.RowSelectorSettings> <igGrid:RowSelectorSettings Visibility="Visible" EnableRowNumbering="False"/> </igGrid:XamGrid.RowSelectorSettings> <igGrid:XamGrid.ColumnMovingSettings> <igGrid:ColumnMovingSettings AllowColumnMoving="Disabled"/> </igGrid:XamGrid.ColumnMovingSettings> <igGrid:XamGrid.Columns> <igGrid:DateColumn Key="DateEntered" HeaderText="Date Entered"/> <igGrid:TextColumn Key="Entry" TextWrapping="Wrap" Width="*"/> </igGrid:XamGrid.Columns> </igGrid:XamGrid>
Hi,
Could you provide the code which performs submitting the rows?
I am guessing that you are using RIA services, but in this case, why are you data binding the Grid to separate collection:
this.myXamGrid.ItemsSource= new ObservableCollection<EntityObject>(EntityObjectCollection);
Thanks,
I am trying to mirror the add a new row sample available on the infragistics website. The reason I am databinding the grid to an observable collection is because the query returns as an IEnumerable. However, with an IEnumerable, you can't add rows. Here is my query code: private void MyQuery() { EntityQuery<EntityObject> query = context.GetEntityObjectByCaseIDQuery(CaseID); context.Load<EntityObject>(query, OnLoaded, null); } private void OnLoaded(LoadOperation<EntityObject> loadOp) { if (loadOp.HasError) { // Log error; return; System.Diagnostics.Debug.WriteLine("CaseViewModel - OnLoaded callback:" + loadOp.Error.Message.ToString()); } else { if (CurrentCase != null && CurrentCase == loadOp.UserState as Case) { foreach (EntityObject entityObject in loadOp.Entities as IEnumerable<EntityObject>) { DataContect.Add(entityObject ); } } }So in order to add, from what I understand, xamgrid needs a collection which inherits IList. Therefore, I convert the itemsource of the data grid to ObservableCollection.Like the sample code on the infragistics page, there is no code on the code behind it is all done through the xaml.
Have you tried binding the XamGrid to the DomainDataSource object's Data property directly, the XamGrid should be able to add rows out of the box?
Note that your DomainService needs to implement the operations you would like to use (e.g. Create, Update, Delete).
Here is some sample code:
[EnableClientAccess()]
public class DomainService1 : DomainService
{
[Query]
public IEnumerable<TestData> GetData()
return TestDataSource.Current;
}
[Update]
public void UpdateData(TestData data)
var existingData = TestDataSource.Current.Single(d => d.IntegerData == data.IntegerData);
int index = TestDataSource.Current.IndexOf(existingData);
TestDataSource.Current[index] = data;
[Insert]
public void InsertData(TestData data)
TestDataSource.Current.Add(data);
[Delete]
public void DeleteData(TestData data)
TestDataSource.Current.Remove(existingData);
<ig:XamGrid x:Name="TestXamGrid"
ItemsSource="{Binding ElementName=testDataDomainDataSource, Path=Data}">
<ig:XamGrid.AddNewRowSettings>
<ig:AddNewRowSettings AllowAddNewRow="Top"/>
</ig:XamGrid.AddNewRowSettings>
</ig:XamGrid>
<riaControls:DomainDataSource
d:DesignData="{d:DesignInstance my:TestData, CreateList=true}"
Height="0"
LoadedData="testDataDomainDataSource_LoadedData"
Name="testDataDomainDataSource"
QueryName="GetDataQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:DomainService1 />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
HTH,