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

RadListview Item Selection and Deselction

4 Answers 620 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ganesh
Top achievements
Rank 1
Ganesh asked on 16 Aug 2017, 06:18 AM

Hi,

I have implemented a RadListview with Selection mode Multiple.

when user select an Item the Item is selecting as per the selection mode and selection Gesture which is fine.

But now I have a scenario to some items to not select when user try to select it even selection mode is enabled, instead it should be in deselection mode. It should check the flag from Itemsource  of the listview Item and disable that Item programatically it should show a toast message like which is not selectable.

Help me out to implement this scenario and suggest me the approaches if any.

 

Thanks,

4 Answers, 1 is accepted

Sort by
0
Ganesh
Top achievements
Rank 1
answered on 16 Aug 2017, 12:40 PM

Hi There is an option in Xamarin Forms ListView like below to deselect the list Item

          if (e.Item == null) return;

          //Add some condition logic based on your requirement here//like ---->

           if(((ListView)sender).SelectedItem.value == "none")

                    ((ListView)sender).SelectedItem = null;

But same option is throwing an exception with RadListView like below

                  ((RadListView)sender).SelectedItem = null;  

  It seems there is no set functionality of the RadListview SelectedItem.

Please provide the solution or how to implement this using RadListView?

 

Thanks,

 

0
Nikolay Demirev
Telerik team
answered on 18 Aug 2017, 03:41 PM
Hi Ganesh,

You could use the following code snippet to clear the selected items:
this.listView.SelectionChanged += (sender, e) => {
                if (this.listView.SelectedItem != null)
                {
                    if (this.listView.SelectedItems.Count() > 0)
                    {
                        this.listView.SelectedItems.Clear();
                    }
                }
            };

If you want to deselect specific item you could just remove it from the collection.

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
Craig Neblett
Top achievements
Rank 1
answered on 01 Dec 2017, 12:43 AM
This means of clearing the selection no longer seems to work using the latest version of UI with the most recent version of Xamarin.Forms. You can clear the collection and set SelectedItem to null, but the item remains visually selected in the list view. Can you provide guidance on how the selection can be cleared?
1
Nikolay Demirev
Telerik team
answered on 05 Dec 2017, 12:17 PM
Hello Craig,

I can confirm, there is an issue clearing the selection with the code snippet I have sent is no longer working. We will investigate the issue, but meanwhile, you could workaround the issue easily using the following code snippet:

if (this.listView.SelectedItem != null)
{
    if (this.listView.SelectedItems.Count() > 2)
    {
        Device.BeginInvokeOnMainThread(() =>
        {
            this.listView.SelectedItems.Clear();
        });
    }
}

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
Tags
ListView
Asked by
Ganesh
Top achievements
Rank 1
Answers by
Ganesh
Top achievements
Rank 1
Nikolay Demirev
Telerik team
Craig Neblett
Top achievements
Rank 1
Share this question
or