Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
How to unfocus an item
My interface looks like this:
The behaviour is a follows:
when you press the Add button and no item in the tree has focus, the program will add a new node at the root level. When you press the Add button and an item has focus, then the program will add a new node below the item with focus.
I want the user to be able to do either of these things repeatedly.
The problem is, once an item gets focus, I can't programmatically unfocus it. Which means that the user cannot add a new node at the root level, since there is no way for the program to unfocus an item.
I want the user to be able to unfocus the item when they click on the white area. When this happens, i call these 2 lines of code, which should unfocus the item:
Set_Property(tree_ctrl$, "OLE.SelectedItems", "")
Set_Property(tree_ctrl$, "OLE.FocusItem", "")
But the item with focus retains focus. Surely it's possible, but I am doing something wrong?
The behaviour is a follows:
when you press the Add button and no item in the tree has focus, the program will add a new node at the root level. When you press the Add button and an item has focus, then the program will add a new node below the item with focus.
I want the user to be able to do either of these things repeatedly.
The problem is, once an item gets focus, I can't programmatically unfocus it. Which means that the user cannot add a new node at the root level, since there is no way for the program to unfocus an item.
I want the user to be able to unfocus the item when they click on the white area. When this happens, i call these 2 lines of code, which should unfocus the item:
Set_Property(tree_ctrl$, "OLE.SelectedItems", "")
Set_Property(tree_ctrl$, "OLE.FocusItem", "")
But the item with focus retains focus. Surely it's possible, but I am doing something wrong?
Comments
Give your UI design, I recommend using selection instead of focus. That way, the user clicks an item to select it, then clicks add to add an item. Adding items won't mess with selection, so you won't encounter the issue you are having now. Moreover, selection is much easier to see than focus.
Hi, the problem with using selection is that, as soon as I press the Add button, the selection goes away.
thanks for your help.
Visually it does, but you're saying that get_Property(tree_ctrl$, "OLE.SelectedItems") shoudl still contain what was selected before the button was clicked?
I did not notice this. For me, that code returns an empty string.
Anyway, all of this can be avoided by using context menus...rather than pressing a button outside of the control. Context menus are the way to go imo.