简体   繁体   中英

How do you force a XUL tree to scroll in code?

I have an app written in XUL which contains a custom tree view that has many items. I've got a button that allows the selected item to be removed but my problem is that whenever this button is pressed, the tree gets scrolled all the way to the top. I have tried to fix this by re-selecting the item at the old index, but unfortunately this does not scroll the view. Is there a way I can get the tree view to either not scroll to the top or force it to re-scroll back to the original position?

My code looks something like this:

onRemoveNilSelection: function(event) {
  var selectedIndex = this._tree.currentIndex;
  this._treeView.removeItem(selectedIndex);
  this._tree.view = this._treeView;
  this._treeView.selection.select(selectedIndex);
},

Use the boxObject's scrollToRow() function .

If your tree is at this._tree,

this._tree.boxObject.scrollToRow(selectedIndex);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM