Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My UserForm has a TreeView. A node is selected, has blue background
color, and is fully alive. But if I minimize the form (thanks to Bullen's FormFun) then restore it, the node is still selected (.SelectedItem.Selected = True), but it's grayed out and focus has gone somewhere else. Pressing the Up/Down keys does nothing. But if I press TAB, focus then jumps to the next control on the form. Pressing Shift-TAB then returns me to the node AND its color and focus are happily restored. So programmatically, how do I 1) force focus back on the node, or better 2) prevent focus from going away UNLESS and until another node is selected? I've tried various things and they all fail, e.g.: with TreeView if .Enabled and .Visible and (.Nodes.Count 0) then 1) TreeView.SetFocus 2) SelectedItem.Selected = True 3) SelectedItem.Visible = False followed by ditto = True. (Fails because, at least for me, .Visible is read-only at run-time). 4) SelectedItem.Checked = True followed by = False. 5) Moving focus away & back again with: Set S = .SelectedItem ..Nodes.Item(S.Index - 1).Selected = True S.Selected = True 6) UserForm.Repaint ....quack quack. Thanks much. *** |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this. Not tested, but it should work.
In the Form module: ----------------------------- Option Explicit Private lFormHwnd As Long Private Declare Function FindWindow _ Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Public Property Let propFormHwnd(lHwnd As Long) lFormHwnd = lHwnd End Property Public Property Get propFormHwnd() As Long propFormHwnd = lFormHwnd End Property Private Sub Userform_Initialize() If Val(Application.Version) = 9 Then Me. propFormHwnd = FindWindow("ThunderDFrame", strCaption) Else Me. propFormHwnd = FindWindow("ThunderXFrame", strCaption) End If End Sub In a normal module: --------------------------- Option Explicit Private Declare Function Putfocus Lib "user32" _ Alias "SetFocus" (ByVal hWnd As Long) As Long Sub FocusTreeview() Putfocus Form1.propFormHwnd With Form1 .txtDummy.SetFocus .TreeView1.SetFocus End With End Sub Where txtDummy is an invisible dummy textbox. RBS wrote in message ... My UserForm has a TreeView. A node is selected, has blue background color, and is fully alive. But if I minimize the form (thanks to Bullen's FormFun) then restore it, the node is still selected (.SelectedItem.Selected = True), but it's grayed out and focus has gone somewhere else. Pressing the Up/Down keys does nothing. But if I press TAB, focus then jumps to the next control on the form. Pressing Shift-TAB then returns me to the node AND its color and focus are happily restored. So programmatically, how do I 1) force focus back on the node, or better 2) prevent focus from going away UNLESS and until another node is selected? I've tried various things and they all fail, e.g.: with TreeView if .Enabled and .Visible and (.Nodes.Count 0) then 1) TreeView.SetFocus 2) SelectedItem.Selected = True 3) SelectedItem.Visible = False followed by ditto = True. (Fails because, at least for me, .Visible is read-only at run-time). 4) SelectedItem.Checked = True followed by = False. 5) Moving focus away & back again with: Set S = .SelectedItem .Nodes.Item(S.Index - 1).Selected = True S.Selected = True 6) UserForm.Repaint ...quack quack. Thanks much. *** |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
RB:
Thanks VERY much. Will try. *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Extracting Relative Propert of TreeView Node | Excel Programming | |||
treeview node tag hold array? | Excel Programming | |||
delete a node in treeview | Excel Programming | |||
How to add a sub-node of a treeview control | Excel Programming | |||
TreeView: add more than one node to nodes collection | Excel Programming |