This is a migrated thread and some comments may be shown as answers.

got double record when add a record via RadGrid

2 Answers 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
SweNz
Top achievements
Rank 1
SweNz asked on 09 Jan 2011, 11:00 AM
Hello guys ,

My problem is when I add a record via RadGrid (property ShowInsertRow="True") then the result on RadGrid show 2 rows with same data.

Eg.

1. click add new record and fill in some data. > http://img814.imageshack.us/i/85624215.png/

2. after I press ENTER button and click on column header (sorting) I got this result. > http://img708.imageshack.us/i/96015502.png/

3. repeat step 1 and 2. I got this result > http://img214.imageshack.us/i/71641655.png/

XAML :
<telerik:RadGridView x:Name="CodeRadGrid" IsReadOnly="False" AutoGenerateColumns="False" SelectionMode="Extended" telerik:StyleManager.Theme="Office_Blue"
ItemsSource="{Binding PagedSource, ElementName=ctlDataPager}" ShowInsertRow="True" AddingNewDataItem="CodeRadGrid_AddingNewDataItem"
RowEditEnded="CodeRadGrid_RowEditEnded" >
<telerik:RadGridView.Columns>
   <telerik:GridViewSelectColumn />
       <telerik:GridViewDataColumn DataMemberBinding="{Binding aCode}" Header="A Code"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding bCode}" Header="B Code">
    </telerik:GridViewDataColumn>
 </telerik:RadGridView.Columns>
 </telerik:RadGridView>
 <telerik:RadDataPager x:Name="RadDataPager" PageSize="7" DisplayMode="First, Last, Next, Previous, Text" IsTotalItemCountFixed="True" />

C#
private void CodeRadGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
    e.NewObject = new CodeObj();
}
 
private void CodeRadGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
{
    if (e.EditAction == GridViewEditAction.Cancel)
    {
        return;
    }
    if (e.EditOperationType == GridViewEditOperationType.Insert)
    {
        ((List<CodeObj>)this.RadDataPager.Source).Add( (CodeObj) e.NewData);
    }
}

My RadDataPager.Source  is List<CodeObj>.

Please give me some advice.

Thank you

SweNz

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 10 Jan 2011, 03:54 PM
Hello SweNz,

Generally, you do not need to handle the RowEditEnded in this case. Once you remove the line:

((List<Player>)this.RadDataPager.Source).Add((Player)e.NewData);

everything should work as expected.
 

Regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
SweNz
Top achievements
Rank 1
answered on 11 Jan 2011, 07:40 AM
Hello Maya,

It works great ! Thanks for your reply

Cheers,

SweNz
Tags
GridView
Asked by
SweNz
Top achievements
Rank 1
Answers by
Maya
Telerik team
SweNz
Top achievements
Rank 1
Share this question
or