TreeNode.EnsureVisible workaround?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

As far as I can tell neither the TreeView nor the TreeNode objects
provide a method for ensuring the visibility of a particular node.
Programmatically selecting a node has no effect on visibility
(scrolling).

Can anyone provide a workaround for this?

Thanks in advance,
Michael
 
Setting the SelectedNode property to the node you want to scroll to works on
my CE device and the emulator (and the desktop)...
Care to share the code you are trying?

Cheers
Daniel
 
Michael,

"TreeView1.SelectedNode = SomeTreeeNode" should do the trick. It scrolls
and opens up to that level and node for me.

One thing that it does not do that I would like to ask this astute group of
developers is how do you set the TreeView control with focus so that the
selected node is displayed with the highlighted coloring? Until I tap on
the control I cannot tell *which* of the nodes is selected.

Rick
 
The control has a Focus method that can be used to set the focus to a
control.

David Wrighton
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Rick" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: TreeNode.EnsureVisible workaround?
| Date: Wed, 20 Aug 2003 16:51:18 -0500
| Lines: 31
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 216-107-127-200.wan.networktel.net 216.107.127.200
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:31474
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Michael,
|
| "TreeView1.SelectedNode = SomeTreeeNode" should do the trick. It scrolls
| and opens up to that level and node for me.
|
| One thing that it does not do that I would like to ask this astute group
of
| developers is how do you set the TreeView control with focus so that the
| selected node is displayed with the highlighted coloring? Until I tap on
| the control I cannot tell *which* of the nodes is selected.
|
| Rick
|
|
| | > No. As I stated in my original post, "Programmatically selecting a node
| > has no effect on visibility
| > (scrolling)."
| >
| > That is to say that selecting a node by any of the several mechanisms
| > provided does not cause it to becomve visible (scrolled to).
| >
| > Any other thoughts?
| >
| > Michael
| >
| >
| >
| > Don't just participate in USENET...get rewarded for it!
|
|
|
 
Hi

If you are looking for the HideSelection property you'll find that it is
true for the listview and false for the treeview by default and not exposed
to us on the CF...

However, you can use GetWindowLong and SetWindowLong to turn it on... Here
is some VB code to place in the form that contains your TreeView1...

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
MyBase.OnGotFocus(e)
Static doneOnce As Boolean
If Not TreeView1 Is Nothing Then
TreeView1.Focus()
If doneOnce = False Then
doneOnce = True
Dim hWnd As IntPtr = Win32Api.GetFocus()
Dim lS As Int32 = Win32Api.GetWindowLong(hWnd, -16)
lS = lS Or &H20
Win32Api.SetWindowLong(hWnd, -16, lS)
End If
End If
End Sub

Cheers
Daniel
 
Daniel,

You're the man! Thanks :-)

Rick


Daniel Moth said:
Hi

If you are looking for the HideSelection property you'll find that it is
true for the listview and false for the treeview by default and not exposed
to us on the CF...

However, you can use GetWindowLong and SetWindowLong to turn it on... Here
is some VB code to place in the form that contains your TreeView1...

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
MyBase.OnGotFocus(e)
Static doneOnce As Boolean
If Not TreeView1 Is Nothing Then
TreeView1.Focus()
If doneOnce = False Then
doneOnce = True
Dim hWnd As IntPtr = Win32Api.GetFocus()
Dim lS As Int32 = Win32Api.GetWindowLong(hWnd, -16)
lS = lS Or &H20
Win32Api.SetWindowLong(hWnd, -16, lS)
End If
End If
End Sub

Cheers
Daniel
 
Back
Top