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

Disable selection of certain items

3 Answers 47 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 12 Jan 2021, 10:28 AM
Is it possible to prevent selection of certain items that we have bound a listview to a custom observable collection based on an property in the item?

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 12 Jan 2021, 03:39 PM

Hi Peter,

You can override the ItemTap Command and execute the default logic ( which is selecting the item) according to the item's properties. Here is an example of creating a custom ListView command: Using the ListViewCommand class.

Inside the Execute method you can access the tapped item and call this.Owner.CommandService.ExecuteDefaultCommand(this.Id, parameter); based on its properties.

In addition, you can style the items differently through the ItemStyleSelector property to mark them as non-selectable.

I hope I was of help.

Regards,
Yana
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Peter
Top achievements
Rank 1
answered on 12 Jan 2021, 03:43 PM
Hello Yana, thanks for the response, I like the idea of making them non-selectable rather than after selecting change behaviour, do you have an example of how to make an item non-selectable, please?
0
Accepted
Yana
Telerik team
answered on 12 Jan 2021, 04:06 PM

Hi Peter,

I am sorry, I didn't explain it clearly, what I meant is through ItemStyleSelector you can make the items visually look unselectable.  Other than that, the only way to actually prevent selection is through the ListView ItemTap command.

I've attached a small example to show you exactly what I mean. Please download the attachment and give it a try.

Let me know if I can assist you with anything else.

Regards,
Yana
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ListView
Asked by
Peter
Top achievements
Rank 1
Answers by
Yana
Telerik team
Peter
Top achievements
Rank 1
Share this question
or