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

[Solved] Infinite Loop when trying to AddNewDataItem

1 Answer 144 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul Dyksterhouse
Top achievements
Rank 1
Paul Dyksterhouse asked on 07 Jan 2010, 08:47 PM
Hello,

I'm trying to add a new row to a GridView that is nested in the RowDetails of a parent GridView but when I call the AddingNewDataItem Handler it gets caught in an infinite loop. Any ideas as to why?

XAML
 <!-- Nested GridView -->
<telerik:RadGridView x:Name="FinishedGoodComponentsGrid"  
   ShowGroupPanel="False" 
   RowIndicatorVisibility="Collapsed"  
   ItemsSource="{Binding FinishedGoodComponents, Mode=TwoWay}" 
   AutoGenerateColumns="False" 
   IsFilteringAllowed="False" 
   RowEditEnded="GridRowEditEnded" 
   ShowInsertRow="True" 
   AddingNewDataItem="FinishedGoodComponentsGridAddingNewDataItem" 
   CanUserFreezeColumns="False"  
   Margin="0" 
   Grid.Row="2" 
   Width="870"
   <telerik:RadGridView.Columns> 
      <telerik:GridViewComboBoxColumn  
         Header="Component" 
         DataMemberBinding="{Binding FinishedGoodId}" 
         UniqueName="Component" 
         SelectedValueMemberPath="Id" 
         DisplayMemberPath="InventoryNumber"/> 
      <telerik:GridViewDataColumn Header="Qty" DataMemberBinding="{Binding Qty}"/> 
   </telerik:RadGridView.Columns> 
</telerik:RadGridView> 

C#
private void FinishedGoodComponentsGridAddingNewDataItem(object sender, GridViewAddingNewEventArgs e) 
{
   e.Cancel = true
   MessageBox.Show("Add Row Pushed"); 
   /* var finishedGood = (FinishedGood)FinishedGoodsGrid.SelectedItem;
   var finishedGoodComponent = new FinishedGoodComponent { FinishedGood = finishedGood, FinishedGoodId = finishedGood.Id };
   finishedGood.FinishedGoodComponents.Add(finishedGoodComponent);*/ 
 
    
   var finishedGoodComponentsGrid = (RadGridView)sender; 
   finishedGoodComponentsGrid.BeginInsert(); 
   //TODO: why I have to do this to make the new row show in edit mode is beyond me.  Work with Telerik on this.
   /*Dispatcher.BeginInvoke(
   delegate
   {
      var row = (GridViewRow)componentGrid.ItemContainerGenerator.ContainerFromItem(finishedGoodComponent);
      ((GridViewCell)row.Cells[0]).IsCurrent = true;
      componentGrid.BeginEdit();
   }
   );*/
 

FYI - I'm using Q3 2009.3 1208

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 11 Jan 2010, 04:30 PM
Hello Paul Dyksterhouse,

Whenever you call BeginInsert RadGridView will try to insert a new row into the grid and the AddingNewdataItem event will be raised. To eliminate the infinite loop you should remove the BeginInsert call from the event handler.


All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Paul Dyksterhouse
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or