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
1770
Index not properly updating when new record is added
posted

Hello. I have the following xamDataGrid:

<igWPF:XamDataGrid 
Name="SecurityGrid" 
GroupByAreaLocation="None" 
DataSource="{Binding UserInfoData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings HighlightAlternateRecords="True" 
AutoGenerateFields="False" 
AllowAddNew="True" 
AddNewRecordLocation="OnTopFixed"/>
</igWPF:XamDataGrid.FieldLayoutSettings>

<igWPF:XamDataGrid.Resources>
<ContextMenu x:Key="RecordContextMenu">

<MenuItem Header="Delete User" 
Name="DeleteRecord"
Command="{Binding DataPresenter.DataContext.DeleteUserommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Self},Path=Parent.PlacementTarget.Record}">
</MenuItem>

</ContextMenu>

</igWPF:XamDataGrid.Resources>

</igWPF:XamDataGrid>

ViewModel like so

private ObservableCollection<UserInfo> _userInfoData;

public ObservableCollection<UserInfo> UserInfoData 
{
get { return _userInfoData; }
set { Set(() => UserInfoData, ref _userInfoData, value); }
}

private void OnDeleteUser(DataRecord record)
{

var index = record.Index;

UserInfoData.RemoveAt(index)

}

When I attempt to delete a record BEFORE I add a record using the build in control activated by AllowAddNew, the index points to the appropriate record I right clicked on. When I add a new record then try to delete that record the record underneath is deleted. The index passes back is the correct index on the grid but points to the wrong record in the collection. The strange thing is that when I save change to the database the newly created record shows up.

Why is the index off after a new record is added?