Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default TreeView node is Selected but grayed out--how set focus?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default TreeView node is Selected but grayed out--how set focus?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default TreeView node is Selected but grayed out--how set focus?

RB:

Thanks VERY much. Will try.

***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Relative Propert of TreeView Node ExcelMonkey Excel Programming 1 March 30th 07 12:26 AM
treeview node tag hold array? RB Smissaert Excel Programming 5 June 27th 05 12:32 AM
delete a node in treeview mark Excel Programming 1 May 15th 05 04:10 AM
How to add a sub-node of a treeview control JohnDing[_2_] Excel Programming 1 December 20th 04 09:30 AM
TreeView: add more than one node to nodes collection Peter[_25_] Excel Programming 3 September 5th 03 12:15 PM


All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"