I have a viewmodel with a property which is bound ...
# tornadofx
m
I have a viewmodel with a property which is bound to a (possibly mutiple) selection in a ListView. The property is bound like this:
Copy code
selectionViewModel.indices.bind(selectionModel.selectedIndices) {
    MyKindOfIndex(it)
}
This is causing all sorts of problems. If I select few items in sequence in the listview, then I select an item before them, I get an exception. If I update the observable list that is used as items list of the listview, the selection is messed up. Is what I'm doing inherently wrong? Is there a better way?
m
Hmm...I would need to see more of the code
but I'm willing to bet you just can't bind like that
you would need to do something like "onChange { selectionModel.select(it)) }"
m
I guess so, even if I don't understand the reason. I ended up saving the selection, deselecting, operating on the backing list and reselecting. Now I'm in the process of switching to a custom control.
Thanks for the feedback.
m
that sounds about right
I know I have done things like reordered the observable list backing a table and had to reselect the previously selected elements