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

RadListView with List<T> items

5 Answers 147 Views
ListView
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 27 Jun 2018, 03:58 PM
Hello,

I am getting System.ArgumentNullException: Value cannot be null. on using RadListView with List<T> items.

I am using project with multiselect listview, and it is working with basic xamarin ListView, which I want to replace with telerik RadListView.

How I can correctly use RadListView instead of Listview in SelectMultipleBasePage.
ProjectMultiselectExample on github
Example of code:
public List<WrappedSelection<T>> WrappedItems = new List<WrappedSelection<T>>();
public SelectMultipleBasePage(List<T> items)
        {
            WrappedItems = items.Select(item => new WrappedSelection<T>() { Item = item, IsSelected = false }).ToList();
            ListView mainList = new ListView()
            {
                ItemsSource = WrappedItems,
                ItemTemplate = new DataTemplate(typeof(WrappedItemSelectionTemplate)),
            };

            mainList.ItemSelected += (sender, e) =>
            {
                if (e.SelectedItem == null) return;
                var o = (WrappedSelection<T>)e.SelectedItem;
                o.IsSelected = !o.IsSelected;
                ((ListView)sender).SelectedItem = null; //de-select
            };
            Content = mainList;
        }

5 Answers, 1 is accepted

Sort by
0
Nikolay Demirev
Telerik team
answered on 29 Jun 2018, 12:39 PM
Hello Dmitriy,

I have reviewed your project, and I have updated it in order to work with the RadListView. The changes I have applied are:

1. Replaced the ListView with RadListView
2. Updated the SelectionChanged event handler, so it works with the API of the RadListView
3. Changed the base type of WrappedItemSelectionTemplate so now it delivers from ListViewTemplateCell
4. Defined a Layout definition so the items are with almost the same size as with the ListView

You can find the modified project attached.

I hope this helps. 

Regards,
Nikolay Demirev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
n/a
Top achievements
Rank 1
answered on 30 Jun 2018, 03:39 PM
Hello Nikolay ,

[quote]2. Updated the SelectionChanged event handler, so it works with the API of the RadListView [/quote]
System.InvalidCastException: Specified cast is not valid.
Getting this expection on cell clicking.

May I also to ask you to add an example with RadListView Filtering feature in this multiselect page?
0
Nikolay Demirev
Telerik team
answered on 02 Jul 2018, 09:04 AM
Hi Dmitriy,

Could you tell me how are you reproducing the InvalidCastException, because I have tested again the project I have sent to you, and I am able to toggle selected items one by one or using the "All" and "None" buttons?

I have modified the same project again, so it filters the selected items. Here is the required code for implementing the filtering:

This code snippet sets the filtering descriptor and provides a callback for the filtering logic
 
mainList.FilterDescriptors.Add(new DelegateFilterDescriptor { Filter = this.Filter });
And here it is the filtering logic:
private bool Filter(object arg)
{
    var item = (WrappedSelection<T>)arg;
    return !item.IsSelected;
}

I am attaching the sample project.
I hope this helps.

Regards,
Nikolay Demirev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
n/a
Top achievements
Rank 1
answered on 05 Jul 2018, 07:52 PM

Hello Nikolay,

Is it possible to filter RadListView in your example by "Name" of items?
[quote]Could you tell me how are you reproducing the InvalidCastException[/quote]
On switcher clicking it works well, but on cell click I have these exceptions:
Android: System.NullReferenceException
iOS: System.InvalidCastException
I added video with my steps here:
https://drive.google.com/open?id=12FwPM4THXn4nABWrDONidlZZcFug4onS

0
Accepted
Nikolay Demirev
Telerik team
answered on 09 Jul 2018, 08:14 AM
Hi Dimitriy,

I didn't reproduce the issue, because I was toggling only the switches. So now I have updated the SelectionChanged event handler. You can check it in the attached project. There were two issues in it. One was the wrong condition checking if there are no new selected items that were causing a NullReferenceException and the other was casting the sender to ListView instead of RadListView.

As for the filtering, you can filter by any property you want. Just modify the Filter method to return true if you want the item to be visible. In the sample project, the selected items are filtered. Here is the documentation article explaining how the filtering in the RadListView can be used.

Is there anything else I can help you with?

Regards,
Nikolay Demirev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ListView
Asked by
n/a
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
n/a
Top achievements
Rank 1
Share this question
or