2

I have found this function shown below very useful to move down in a treeview, but I ask here if there is a move up function.

def moveDown(self):
    curSelection = self.tree.selection() # current row - from /68508694/
    nextSelection = self.tree.next(curSelection) # next row
    self.tree.selection_set(nextSelection) # set the next row to be the current row
    self.tree.see(nextSelection) # make sure the current row is shown - from /10155153/
0

1 Answer 1

1

Change this nextSelection = self.tree.next to this prevSelection = self.tree.prev and you should check for nulls, see comments:

def moveUp(self):
    curSelection = self.tree.selection()  # Get the current selection
    if not curSelection:  # If no row is selected, exit
        return
    
    prevSelection = self.tree.prev(curSelection)  # Get the previous row
    if prevSelection:  # Check if there's a previous row
        self.tree.selection_set(prevSelection)
        self.tree.see(prevSelection) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.