Ritu Singh
Solution
Suppose we have two rows here, the primary row is the parent row, and the secondary row is the children row.
When you select the children row and delete children after that, the table switches and focuses on the parent row. In case you want to keep focus on the children row (i.e., the secondary row), you have to write the code as below.
If you want to keep the focus on a child row in a tree structure after deleting another child row, you will need to make sure you that you already set the focus on the right child row. To make your code work you have to do the below changes in your code
Find out which row is currently selected before you delete a child row. This information will be utilized at a later time in order to reset the focus.
Delete the Row of the Targeted Child: Continue with the process of deleting the row of the targeted child.
After the deletion, you should return the focus to a child row that is still present in the table. This is done by setting the focus back to the row in question. If you delete the row that you had previously selected, you may be required to choose a new row to concentrate on, such as the sibling that came before or after it, or the parent row.
This code uses tree.next(selected_item) to get the ID of the next row after the one being deleted. Then, it sets the focus and selection to the next row, effectively maintaining the focus on the children row. Adjust this code according to your specific GUI framework if you are using something other than tkinter.
Suggested blogs:
>How can I iterate over enum Flag alias?
>How to train a deep learning in case validation with Pytorch result NaN or high loss?s
>Fixing QVariant output issue in Python
>Removing ASCII formatted characters from my CAN messages in Python
>Why `import` does not work in this case (in `exec`)?
>Fix my form calling the wrong Django view error
>How to load static files using Nginx, Docker, and Django?
>How to tell Django "if anything in URL patterns does not match the GET string?
>How can I browser to render links in streamed content in Django?
>Access the "model" attribute for a ListView in Django for template
>How to use a function to print S3 data to HTML using Django?