How to bind LisView's selectedItem property?

I’m trying to bind selectedItem property of ListView with ToSource binding type but it’s not working.

<Bindings>
    <engine:DataBinding property="itemsSource" data-source-path="Profiles" />
    <engine:DataBinding property="selectedItem" data-source-path="SelectedProfile" binding-mode="ToSource" />
</Bindings>
[CreateProperty]
public GameProfileData SelectedProfile
{
    get => _selectedProfile;
    set
    {
        Debug.Log(value);
        SetProperty(ref _selectedProfile, value);
    }
}

What am I doing wrong?

Also why I can reorder items in LIstView even though Reorderable property is false?

I’m trying to bind selectedItem property of ListView with ToSource binding type but it’s not working.

The selectedItem is a read-only property. To switch the selection to another item, you can use selectedIndex instead.

Also why I can reorder items in LIstView even though Reorderable property is false?

I believe this is a regression that will be fixed through The list remains orderable when NonReorderableAttribute is used.

Ok, I probably don’t understand something. I was under impression that if I bind selectedIndex to my SelectedProfileIndex property with ToSource binding mode then when I click on item in ListView SelectedProfileIndex would be updated with index of item I’ve clicked. Apparently this is not how it works? Because clicking on items does nothing for me. With ToTarget mode it works as expected, changing SelectedProfileIndex is changing selected item in LIstView.

Yeah I think I have this bug, thanks for letting me know.

Ok, I probably don’t understand something. I was under impression that if I bind selectedIndex to my SelectedProfileIndex property with ToSource binding mode then when I click on item in ListView SelectedProfileIndex would be updated with index of item I’ve clicked. Apparently this is not how it works? Because clicking on items does nothing for me. With ToTarget mode it works as expected, changing SelectedProfileIndex is changing selected item in LIstView.

It’s very possible that the selectedIndex property is not correctly propagated as a change if the change is not coming from the property itself. Can you open an issue about that so that the team can take a look?
Thanks!

I made bug report IN-88849. In the process I encountered that property is not updated only when selecting by mouse clicks. Selecting with keyboard navigation is working fine. Btw in test project I encountered new bug. You can see at the start of video Watch ListViewBindingTest | Streamable when clicking on item all items with lower index gets selected one by one. It can be fixed by clicking on another unity window. I have no idea what’s going on here and I don’t have this bug in main project.

Hey @martinpa_unity my bug was closed as duplicate. Just wanted to ask haven’t you looked into what could be the cause of a strange selection behavior at the start of that video? Did you had this issue too? I’m worried I might run into this bug in my main project and it would be nice to know the cause of it.

Oh sorry, I didn’t realize the click issue was already reported, I saw the one they reported as duplicate, but it didn’t mention bindings, so I overlooked it.

Just wanted to ask haven’t you looked into what could be the cause of a strange selection behavior at the start of that video? Did you had this issue too?

Haven’t seen such an issue before, is it reproduceable using the project you sent us? I can check it out and open a bug about it if I can reproduce it.

I get it every time on this test project so it’s reproducible, at least on my PC.

I haven’t been able to repro the issue. When I click on an item, it selects the correct item and it doesn’t move up.

Are you on the latest version?

I’m on 6000.0.23f1. I can update to see if the issue stays.

I have it on 6000.0.26f1 too. I experimented a bit and find out that this issue appears only when active input handling set to both. If I change it to input manager(old) or input system(new) the bug is gone.