MultiColumnListView and MultiColumnTreeView do not change selection on first input when focus is set by code

Description

After a MultiColumnListView or MultiColumnTreeView is populate, index selected, and focused through code, the View will not change the selection with the first input (eg W or S key pressed by default). The View will receive the event, and trigger any registered callbacks, but the selection does not change. Once a single input action is sent, it will respond to subsequent events normally.

It was also observed when attempting to work around the problem, that if a NavigationMoveEvent is sent via code in the first Update() after the Focus() is called on the View, that event also triggers registered callbacks, but does not change the selected item. This will then result in two navigation events that do not change the selection: the one sent by code, and the one sent via user input.

If a NavigationMoveEvent is sent on the 2nd Update() after the Focus(), that event will demonstrate the behavior above, but the first user input event will behave normally.

This behavior was not seen for ListView and TreeView, only the MultiColumn* versions of these views.

How To Reproduce:

  1. Create a GameObject with a UIDocument component
  2. Add a MultiColumnListView (or MultiColumnTreeView) to the document with at least one column, giving the name View
  3. Add a script to the object with the following code:
using UnityEngine;
using UnityEngine.UIElements;
using System.Collections.Generic;
public class MultiColumnExample : MonoBehaviour
{
    public enum Workaround { None, Broken, Working};
    
    public Workaround workaround = Workaround.None;
    UIDocument _Doc;
    List<string> _Items = new() { "one", "two", "three", "four", "five", "six"};
    int _UpdateCount = 0;
    int _UpdateCheck;
    
    void Start()
    {
        _Doc = GetComponent<UIDocument>();
        MultiColumnListView view = _Doc.rootVisualElement.Q<MultiColumnListView>("View");
        view.itemsSource = _Items;
        view.RegisterCallback<NavigationMoveEvent>((e) => Debug.Log("Navigation performed: "+e.direction));
        view.SetSelection(0);
        view.Focus();
        _UpdateCheck = workaround switch
        {
            Workaround.Broken => 0,
            Workaround.Working => 1,
            _ => -1
        };
    }

    void Update()
    {
        if (_UpdateCount <= _UpdateCheck)
        {
            if (_UpdateCount == _UpdateCheck)
                using (NavigationMoveEvent evt = NavigationMoveEvent.GetPooled(NavigationMoveEvent.Direction.Down))
                    _Doc.rootVisualElement.SendEvent(evt);
            _UpdateCount++;
        }
    }
}
  1. Run the scene. You will notice that the first W or S key pressed does nothing, then the control behaves normally.
  2. You can change the Workaround selection in the inspector to see the behavior for the 2 workaround attempts

Hi sroebke. Thank you for taking the time to inform us of this problem and for the thorough analysis! Could you report a bug about it please? Thanks!

Will do, thanks