unity treeview expanding and collapsing manually.

So I have a treeview with multiple layers in it and it has custom styling in it. I don’t want to show the arrow on the left that can expand and collapse the items but I want this functionality when I click on an item in the treeview. Now we have the selection change event for which I made a method that also does this. However selection changed does not trigger if you click on the same item twice (which makes sense). But none of the other events same to be able to do this either so how would I be able to do this?

You could register a ClickEvent on your items to detect the click and do the expand/collapse from there.
Here’s some documentation on how to do it: Unity - Manual: Click events
It could also be done just on a PointerDownEvent or PointerUpEvent.

It could look something like this (not tested).

treeView.makeItem = () =>
{
    var element = new MyElement();
    element.RegisterCallback<ClickEvent>(OnItemClicked);
    return element;
};
treeView.bindItem = (element, i) =>
{
    ((MyElement)element).index = i;
};

void OnItemClicked(ClickEvent evt)
{
    var element = evt.target as MyElement;
    treeView.viewController.ExpandItemByIndex(element.index, false);
}

Had to do a bit more work then that but thanks to this I did get to the conclusion thanks