Listview - select item by viewmodel and visible on the screen

1 Answer 58 Views
ListView
Rodrigo
Top achievements
Rank 1
Iron
Iron
Iron
Rodrigo asked on 19 Feb 2024, 08:23 PM

Hi!

How do I select an item in the listview at runtime (mvvm) and make this item always visible on the screen? Can you help me?

Example:
I press a button to select any item from the list. If this item is not appearing on the screen, listview automatically positions it on the item, making it visible.

Regards,

Rodrigo

1 Answer, 1 is accepted

Sort by
1
Didi
Telerik team
answered on 20 Feb 2024, 09:04 AM

Hello Rodrigo,

Telerik ListView provides SelectedItem property which is bindable, so you can define a property in the view model and bind it to the SelectedItem, you can change the value runtime. The property in the view model should be of type the business model. In my case the business model is Client class.

<telerik:RadListView  x:Name="listView" Margin="10"
                              ItemsSource="{Binding Names}"
                              SelectionMode="Multiple"
                              SelectedItem="{Binding SelectedValue, Mode=TwoWay}">
    private Client selectedValue { get; set; }
    public Client SelectedValue 
    { 
        get => this.selectedValue;
        set
        {
            if (this.selectedValue != value)
            {
                this.selectedValue = value;
                OnPropertyChanged();
            }
        }
    }

If you want to scroll to this item, you can use the programmatic scrollingScrollItemIntoView method, and to scroll to the SelectedItem. This is a logic that must me implemented on your side.

I hope the information will be of help.

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ListView
Asked by
Rodrigo
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Didi
Telerik team
Share this question
or