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
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,
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
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