Problem in the RadListView control when the collection of items is emptied.

1 Answer 123 Views
ListView
Comercializadora Paxia
Top achievements
Rank 1
Iron
Comercializadora Paxia asked on 03 Aug 2023, 05:31 PM

Hello I hope you can help me.
I have a RadListView that gets populated from a collection provided in the ViewModel. Within the template there is a button to delete the selected element and it works fine, but when there is only one element left and I delete it, the application crashes.

The xaml of the list


<telerik:RadListView ItemsSource="{Binding SelectedProducts, Mode=TwoWay}"  SelectionMode="None" >
                        <telerik:RadListView.ItemTemplate>
                            <DataTemplate  x:DataType="modles:ProductExhibitionDTO">
                                <telerik:ListViewTemplateCell>
                                    <telerik:ListViewTemplateCell.View>
                                        <Grid BackgroundColor="#FAFAFA" RowDefinitions="auto, auto, *, auto, auto, auto">
                                            <Grid Grid.Row="0" ColumnDefinitions="auto, *, auto">
                                                <Label Grid.Column="0" Text="{Binding ProductNumber}" Margin="8" FontSize="14" FontFamily="RobotoBold" TextColor="#000" />
                                                <Button Grid.Column="2" HorizontalOptions="End" Margin="8" ImageSource="delete_out_6" HeightRequest="24" WidthRequest="24" Command="{Binding Source={RelativeSource AncestorType={x:Type viewModel:NegotiatedExhibitionViewModel}}, Path=DeleteProductCommand}" CommandParameter="{Binding .}" BackgroundColor="Transparent" />
                                            </Grid>
                                            <Grid Grid.Row="1" RowDefinitions="auto, auto, auto" ColumnDefinitions="auto, 3*, *" >
                                                <Image Grid.Row="0" Grid.RowSpan="3" Grid.Column="0"  Source="{Binding ProductImageURL}" HeightRequest="100" WidthRequest="100" Margin="8"/>
                                                <Label Grid.Row="0" Grid.Column="1" VerticalOptions="Start" Margin="8,4" FontSize="12" TextColor="#000" FontFamily="RobotoRegular" Text="{Binding BrandName}" />
                                                <Label Grid.Row="1" Grid.Column="1" VerticalOptions="Start" HorizontalOptions="Fill" Margin="8,4" FontSize="14" TextColor="#000" FontFamily="RobotoBold" Text="{Binding ProductName}" LineBreakMode="WordWrap" />
                                                <Label Grid.Row="2" Grid.Column="1" VerticalOptions="Start" Margin="8,4" FontSize="14" TextColor="#000" FontFamily="RobotoRegular" Text="{Binding GTIN}" />
                                            </Grid>
                                            <Grid Grid.Row="2" ColumnDefinitions=".5*,.5*" RowDefinitions="auto, auto">
                                                <HorizontalStackLayout Grid.Row="0" Grid.Column="0">
                                                    <Label Grid.Row="0" Grid.Column="0" TextTransform ="Uppercase" Margin="8" Text="Frentes" TextColor="#757575" FontSize="10" FontFamily="RobotoRegular" />
                                                    <Image Source="warning_out" IsVisible="{Binding IsFrontRequired,Mode=TwoWay}" Margin="8" HeightRequest="15" WidthRequest="15"/>
                                                </HorizontalStackLayout>
                                                <HorizontalStackLayout Grid.Row="0" Grid.Column="1">
                                                    <Label Grid.Row="0" Grid.Column="1" TextTransform ="Uppercase" Margin="8" Text="Fondos" TextColor="#757575" FontSize="10" FontFamily="RobotoRegular"/>
                                                    <Image Source="warning_out" IsVisible="{Binding IsFundRequired,Mode=TwoWay}" Margin="8" HeightRequest="15" WidthRequest="15"/>
                                                </HorizontalStackLayout>
                                                <telerik:RadBorder Grid.Row="1" Grid.Column="0" Margin="8,4">
                                                    <telerik:RadEntry  Text="{Binding Front}"  Keyboard="Numeric" BackgroundColor="#FFFFFF" FontSize="14" FontFamily="RobotoRegular" WidthRequest="80" HorizontalOptions="Start" ClearButtonVisibility="Never" FocusedBorderBrush="Transparent" IsReadOnly="{Binding IsReadOnly}" />
                                                </telerik:RadBorder>
                                                <telerik:RadBorder Grid.Row="1" Grid.Column="1"  Margin="8,4" >
                                                    <telerik:RadEntry  Text="{Binding Fund}"  Keyboard="Numeric" BackgroundColor="#FFFFFF"  FontSize="14" FontFamily="RobotoRegular" WidthRequest="80" HorizontalOptions="Start" ClearButtonVisibility="Never" FocusedBorderBrush="Transparent" IsReadOnly="{Binding IsReadOnly}" />
                                                </telerik:RadBorder>
                                            </Grid>
                                        </Grid>
                                    </telerik:ListViewTemplateCell.View>
                                </telerik:ListViewTemplateCell>
                            </DataTemplate>
                        </telerik:RadListView.ItemTemplate>
                    </telerik:RadListView>

 The DeleteItem command in the viewModel,


 [RelayCommand]
        void DeleteProduct(Object obj) //ProductExhibitionDTO productExhibitionDTO
        {
            ProductExhibitionDTO productExhibitionDTO = obj as ProductExhibitionDTO;
            if (productExhibitionDTO != null)
            {
                SelectedProducts.Remove(productExhibitionDTO);
            }
        }

 

And finally, the error:

 

 

 

 

Comercializadora Paxia
Top achievements
Rank 1
Iron
commented on 03 Aug 2023, 07:21 PM

This happens more commonly when I have already written values in the RadEntry that are in the template.

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 04 Aug 2023, 11:22 AM

Hi,

I have tested the case and the app does not crash when one item left and then deleted it. The ListView is empty. 

Then I tried this case: I have already written values in the RadEntry that are in the template. And no exception. My sample project is attached. 

Could you please download and test on your side. Let me know the final result. If the issue does not occur in a sample on your side, please modify it so the issue can be reproduced, then attach it to the forum thread. 

Regards,
Didi
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Tags
ListView
Asked by
Comercializadora Paxia
Top achievements
Rank 1
Iron
Answers by
Didi
Telerik team
Share this question
or