Hi,
I have a problem in a Grid, editing a new row previously entered.
The sequence is this :
1. First I insert a new row.
The code in AddingNewDataItem Event Handler of the Grid is :
public void EUGruppoGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
if (e.Cancel) return;
String TipoCurrentItem;
GridViewDataControl GridViewDataControl = e.OwnerGridViewItemsControl;
if (GridViewDataControl.CurrentItem != null)
TipoCurrentItem = ((EUGruppoVO)GridViewDataControl.CurrentItem).Tipo;
else
TipoCurrentItem = " ";
e.NewObject = new EUGruppoVO(0, "", TipoCurrentItem);
}
the "EUGruppoVO" Constructor is :
public EUGruppoVO(Int32 id, String descrizione, String tipo)
{
this._id = id; // in the database the fields is a identity primary key
this._descrizione = descrizione;
this._tipo = tipo;
}
the "EUGruppoVO" implements "INotifyPropertyChanged"
the "EUGruppoItemsSource" is an instance of : "public class EUGruppoVOList : ObservableCollection<EUGruppoVO>"
2. Then I move to another row ( the RowEditEnded Event fire with "e.EditOperationType == GridViewEditOperationType.Insert" )The code in RowEditEnded Event Handler of the Grid is :
public void EUGruppoGrid_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e){if (e.EditAction == GridViewEditAction.Cancel) return;if (e.EditOperationType == GridViewEditOperationType.Insert)_eUGruppoService.Insert((EUGruppoVO)e.NewData);else_eUGruppoService.Update((EUGruppoVO)e.NewData);}
3. Then I move in the row previously entered, strangely the value of the "id" property of the current item has remained zero.I edit the row, when I move to another row the RowEditEnded Event fire again with "e.EditOperationType == GridViewEditOperationType.Update"but the "id" property of (EUGruppoVO)e.NewData is still zero, why ?
An extract of the XAML code is :...<telerikGridView:RadGridView x:Name="EUGruppoGrid" AutoGenerateColumns="False" CanUserFreezeColumns="False" ShowGroupPanel="True" ItemsSource="{Binding EUGruppoItemsSource, Mode=TwoWay}" CurrentItem="{Binding EUGruppoCurrentItem, Mode=TwoWay}" Margin="0,0,0,0"><telerikGridView:RadGridView.Columns><telerikGridView:GridViewComboBoxColumn DataMemberBinding="{Binding Tipo, Mode=TwoWay}" ItemsSource="{Binding TipoEUList, Mode=OneWay}" DisplayMemberPath="Descrizione" SelectedValueMemberPath="Codice" Header="Tipo" IsReadOnly="False" /><telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Descrizione, Mode=TwoWay}" Header="Descrizione" IsReadOnly="False" /><telerikGridView:GridViewDataColumn IsVisible="False" DataMemberBinding="{Binding Id, Mode=OneWay}" Header="Id" IsReadOnly="True" /></telerikGridView:RadGridView.Columns></telerikGridView:RadGridView>...
An extract of the code behind is :...this.EUGruppoGrid.AddingNewDataItem += new EventHandler<Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs>(_tabelleViewModel.Controller.EUGruppoGrid_AddingNewDataItem);this.EUGruppoGrid.RowEditEnded += new EventHandler<Telerik.Windows.Controls.GridViewRowEditEndedEventArgs>(_tabelleViewModel.Controller.EUGruppoGrid_RowEditEnded);...DataContext = _tabelleViewModel
Thanks, Dario.