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

AddinNewDataItem never fired

1 Answer 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
medialog
Top achievements
Rank 2
medialog asked on 21 Mar 2011, 05:10 PM
Hello,

I have a GridView with ItemSource binded.

When i add by the code an element in items "AddingNewDataItem" is not fired.

Is it a bug or the event AddinNewDataItem doesn't fired when item is added by the code??

Players is ObservableCollection<Player>.

I need to preselect the last row and the second column at each insert. I don't know how to make this if AddinNewDataItem doesn't fired.

My version is Q1 2011.


public MainPage()
        {
            playersGrid.AddingNewDataItem += new EventHandler<Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs>(playersGrid_AddingNewDataItem);
        }
 
        void playersGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            //Never fired
        }
 
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            if(playersGrid.DataContext is MyViewModel)
            {
                var viewModel = playersGrid.DataContext as MyViewModel;
                viewModel.Players.Add(new Player("jerome", 10, Position.DF, "France"));
            }
        }


<telerik:RadGridView Name="playersGrid" ShowColumnFooters="True"
                             ItemsSource="{Binding Players}"
                             AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" FooterTextAlignment="Right"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}">
                    <telerik:GridViewDataColumn.Footer>                    
                            <TextBlock Text="{Binding MyProperty,  Source={StaticResource MyViewModel}}" />                                        
                    </telerik:GridViewDataColumn.Footer>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}">
                    <telerik:GridViewDataColumn.FooterCellStyle>
                        <Style TargetType="telerik:GridViewFooterCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <telerik:RadComboBox ItemsSource="{Binding MyItems, Source={StaticResource MyViewModel}}">
                                            <telerik:RadComboBoxItem Content="Item1" />
                                            <telerik:RadComboBoxItem Content="Item2" />
                                            <telerik:RadComboBoxItem Content="Item3" />
                                        </telerik:RadComboBox>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </telerik:GridViewDataColumn.FooterCellStyle>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}">
                    <telerik:GridViewDataColumn.FooterCellStyle>
                        <Style TargetType="telerik:GridViewFooterCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <telerik:RadComboBox >
                                            <telerik:RadComboBoxItem Content="Item1" />
                                            <telerik:RadComboBoxItem Content="Item2" />
                                            <telerik:RadComboBoxItem Content="Item3" />                                            
                                        </telerik:RadComboBox>
                                    </ControlTemplate
                                </Setter.Value>                            
                            </Setter>
                        </Style>                                               
                    </telerik:GridViewDataColumn.FooterCellStyle>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Name="Button1"
                    Content="Do Something 1"
                    Click="Button1_Click"
                    Margin="5"
                    HorizontalAlignment="Left"/>
            <Button Name="Button2"
                    Content="Do Something 2"
                    Click="Button2_Click"
                    Margin="5"
                    HorizontalAlignment="Left"/>
        </StackPanel>

1 Answer, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 21 Mar 2011, 05:23 PM
Hi Jérôme,

 AddingNewDataItem fires only when the user inserts a data item - either through the New Row, or by pressing the Insert key.

Greetings,
Yavor Georgiev
the Telerik team
Tags
GridView
Asked by
medialog
Top achievements
Rank 2
Answers by
Yavor Georgiev
Telerik team
Share this question
or