Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.
currentIndex
Type: integer

Set to the row index of the tree caret in the tree. For trees with focus, the caret's position is indicated by the focus ring, but unfocused trees won't show  a focus ring, naturally. For unfocused trees, the (undrawn) caret's position can still be obtained by this property. If the caret isn't present for any row (for example, because the tree has never been focused), the value will be -1.

You cannot rely on this property to change or determine a tree selection, except for trees with seltype="single". (All trees have seltype="multiple" by default.) To reliably change or determine a selection, instead use the nsITreeSelection interface methods available via tree.view.selection.

Example

// One way of retrieving the text of a cell.
<script language ="javascript">
function treeRowClicked(){
    var tree = document.getElementById("my-tree");
    var selection = tree.view.selection;
    var cellText = tree.view.getCellText(tree.currentIndex, tree.columns.getColumnAt(0));
    alert(cellText);
}
</script>

<tree id="my-tree" seltype="single" onselect="treeRowClicked()">
  <treecols>
    <treecol label="Title" flex="1"/><treecol label="URL" flex="1"/>
  </treecols>
  <treechildren>
    <treeitem>
      <treerow>
        <treecell label="[email protected]"/>
        <treecell label="Top secret plans"/>
      </treerow>
    </treeitem>
    <treeitem>
      <treerow>
        <treecell label="[email protected]"/>
        <treecell label="Let's do lunch"/>
      </treerow>
    </treeitem>
  </treechildren>
</tree>

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, trevorh, Sevenspade, Marsf, MarkFinkle, Ptak82, Pmash, The Hunter, Dria
 Last updated by: Sheppy,