Question

I have two (or more) ListView's that are side by side. I need them to act as one so the selected index of each is always the same.

Was it helpful?

Solution

This should work :), maybe.

var lv1 = ListView {
}
var lv2 = ListView {
}

var onSync = false;    

var sel1 = bind lv1.selectedIndex on replace {
    if (not onSync) {
        onSync = true;
        lv2.select(sel1);
        onSync = false;
    }
}
var sel2 = bind lv2.selectedIndex on replace {
    if (not onSync) {
        onSync = true;
        lv1.select(sel2);
        onSync = false;
    }
}

OTHER TIPS

"bind with inverse" seems to be an option:

var a;
var b = bind a with inverse;

works only for simple expressions. anything more complex will generate a warning/error.

Except that it isn't because of ListView's selectedIndex is public-read (thaks for the correction).

You will have to do it like this:

var lv1 = ListView {
}
var lv2 = ListView {
}
var sel1 = bind lv1.selectedIndex on replace {
    lv2.select(sel1);
}
var sel2 = bind lv2.selectedIndex on replace {
    lv1.select(sel1);
}

You also may want to add some ifs here and there to avoid extra select() calls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top