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

Grid Does not refresh after delete last (added) row

3 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Aleksey
Top achievements
Rank 1
Aleksey asked on 23 Jan 2017, 04:42 AM

Hello!

 

Code from View:

 

<contentPanel:PageContent.Resources>
        <DataTemplate x:Key="CloneRowDataTemplate">
            <telerik:RadButton Command="{Binding AddDetailCommand}" CommandParameter="{Binding}"
                               Style="{StaticResource AddRowButtonStyle}" />
        </DataTemplate>
        <DataTemplate x:Key="RemoveRowDataTemplate">
            <telerik:RadButton Command="{Binding DeleteDetailCommand}" CommandParameter="{Binding}"
                               Style="{StaticResource DeleteRowButtonStyle}"/>
        </DataTemplate>
    </contentPanel:PageContent.Resources>

 

<telerik:RadGridView Grid.Row="0" Grid.Column="1" Width="760" Height="150"
                                     Margin="5,10,5,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                     CanUserDeleteRows="False" IsFilteringAllowed="False"
                                     ItemsSource="{Binding Codes}"
                                     EditTriggers="CellClick" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed"
                                     GroupRenderMode="Flat" ValidatesOnDataErrors="InViewMode"
                                     ScrollViewer.VerticalScrollBarVisibility="Auto" ShowGroupPanel="False">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn Header="Code" Width="120" DataMemberBinding="{Binding Code}"
                                                    IsFilterable="False">
                            <telerik:GridViewColumn.CellEditTemplate>
                                <DataTemplate DataType="codeBackoffReportTemplates:CodeBackoffItemViewModel">
                                    <telerik:RadAutoCompleteBox
                                        ItemsSource="{Binding Path=DataContext.AvailableCodes, RelativeSource={RelativeSource FindAncestor, AncestorType=telerik:RadGridView}}"
                                        SearchText="{Binding Code, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
                                </DataTemplate>
                            </telerik:GridViewColumn.CellEditTemplate>
                        </telerik:GridViewDataColumn>
                        <telerik:GridViewDataColumn Header="Value" Width="140"
                                                    DataMemberBinding="{Binding Backoff, Mode=TwoWay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
                                                    IsFilterable="False"/>
                        <telerik:GridViewColumn Width="50"
                                                IsSortable="False" CellTemplate="{StaticResource CloneRowDataTemplate}"
                                                CellEditTemplate="{StaticResource CloneRowDataTemplate}">
                            <telerik:GridViewColumn.Header>
                                <telerik:RadButton
                                    Command="{Binding Path=DataContext.AddFirstRowCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=telerik:RadGridView}}"
                                    Style="{StaticResource AddRowButtonStyle}" />
                            </telerik:GridViewColumn.Header>
                        </telerik:GridViewColumn>
                        <telerik:GridViewColumn Width="50"
                                                IsSortable="False"
                                                CellTemplate="{StaticResource RemoveRowDataTemplate}"
                                                CellEditTemplate="{StaticResource RemoveRowDataTemplate}" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>

 

Command for deleting row from ViewModel:

 

private ICommand DeleteDetailCommand => new DelegateCommand(DeleteDetail);

 

        private void DeleteDetail(object parameter)
        {
            var code = (CodeItemViewModel)parameter;
            if (code == null)
            {
                return;
            }
            Codes.Remove(code);
        }

  

 

GridView is not refreshed after removing of newly added row (row is already removed but still displayed) (see attached file)

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 24 Jan 2017, 05:00 PM
Hello Aleksey,

I've prepared a sample project based on the code you've provided which successfully removes an item from the bound collection as well as from RadGridView. It's built for the WPF framework but the approach should be similar when using Silverlight. Could you please have a look at it and let me know how it differs from the setup you have at your end?

A possible issue I've discovered is that the DeleteCommand is private which would mean that it could not be bound to the Command of the RadButton as it would result in a binding error. Could you please try changing its access modifier to and see if this solves your issue?

Do let me know how this goes.

Regards,
Dilyan Traykov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Aleksey
Top achievements
Rank 1
answered on 25 Jan 2017, 02:38 AM

Hello, Dilyan!

 

Thank you for your answer.

 

Sorry for confusing: there is the modifier public in real code, it seems that I made this typo while preparing the code for the post.

 

I also noticed, that setting property 'IsSynchronizedWithCurrentItem' to "true" has solved this problem too. Should I expect some side effects in this case?

 

0
Dilyan Traykov
Telerik team
answered on 25 Jan 2017, 01:20 PM
Hello Aleksey,

There should not be any side effects when using the IsSynchronizedWithCurrentItem property.

You can find more information regarding its use in this article.

Regards,
Dilyan Traykov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Aleksey
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Aleksey
Top achievements
Rank 1
Share this question
or