How to deselect RadListView item.

3 posts, 1 answers
  1. Namek
    Namek avatar
    4 posts
    Member since:
    Jul 2016

    Posted 23 Aug Link to this post

    I've started to use RadListView for my app.

    My use case looks more or less:
    - User has a ListView

    - User can tap on any Item of ListView

    - Some business logic is done at given Item

    - User can tap again on any Item of ListView (even if it has been tapped just before)

    For OOTB Xamarin.Forms ListView, I've just use command, binded to *SelectedItem* property of ListView, and after did some business logic, I've just pass *null* as SelectedItem (it informs ListView, that there is still no selection):

    public MyItemObject SelectedItem
            return _selectedItem;
            if (_selectedItem != value)
                _selectedItem = value;
                // Some business logic here
                // Deselect item from ListView
                _selectedItem = null;

    However for *RadListView* it not working properly - it doesn't matter, if I use such "hacky" logic as for *ListView* or not, I had to tap 2 times, after my initial tap, so:
    - User taps at item no. 1 - some logic is performed (OK)

    - User taps again at item no. 1 - nothing is done, except "deselecting" *RadListView* selection (KO)

    - User taps againt at item no. 1 - some logic is performed (OK)

    Is there any possibility, to deselect *RadListView* from code behind?

    Thanks a lot!

  2. Answer
    Vladislav avatar
    274 posts

    Posted 26 Aug Link to this post

    Hi Namek,

    If I understand you correctly you just need/want to execute some business logic on RadListViewItem tap regardless if it was previously selected or not. If this is the case can I suggest to use the RadListView's ItemTapped event which fires every time an item is tapped. Moreover if you don't need/want/use selection of items you can disable it by setting the SelectionMode to "None".

    Please don't hesitate to contact us again if your scenario is different or I didn't understand it properly.

    Telerik by Progress
    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
  3. DevCraft R3 2016 release webinar banner
  4. Namek
    Namek avatar
    4 posts
    Member since:
    Jul 2016

    Posted 26 Aug in reply to Vladislav Link to this post

    Hi Vladislav,
    Actually I've already achieved it exactly as you said:
    1. Inside my XAML.CS code, I've implemented method, for handling event like:

    private void OnItemTapped(object sender, ItemTapEventArgs e)
        if (e?.Item is MyItemObject)
            MyViewModel.SelectedItem = (MyItemObject)e.Item;

    2. I've referenced my method, which handles even at XAML RadListView definition ItemTapped="OnItemTapped"
    3. I've disabled selection of item at XAML RadListView definition SelectionMode="None"

    In such case, I'm just replacing MyViewModel.SelectedItem object, against which I'm doing some business logic in viewmodel.
    Tapping at given item, returning back and tapping again working as expected.

    I tought that there might be more "beauty" solution (I don't like to have lot of code in code behind XAML), but at least it's working :).

    Hope it might help someone else.

    Thanks a lot.

Back to Top