[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

EnsureVisible in TreeView: how to ensure that horiz. scrollbar is aligned left

Posted on 2009-03-31
5
Medium Priority
?
469 Views
Last Modified: 2012-05-06
Hi,

I have a tree view with eg. following nodes

# People
|
+--# Custumers
     |
     +-- # Anne Charles, Hillroad 14, 7766 MyTown, My Country
     |
     +-- # Steve Jones, Forestroad 12, 7766 MyTown, My Country

With the command

    Me.treeViewM.Nodes(0).Nodes(0).Nodes(0).EnsureVisible()

I can ensure that "Anne Charles" is visible within the treeview. My problem is: If the treeview is not wide enough to show the complete node text of this node, the horizontal scroll bar is automatically moved to the right so that node structure shown left from the "A" in the text "Anne Charles" is not visible any more. Thus

    Anne Charles, Hillroad 14, 7766 MyTown, My Country
   
    Steve Jones, Forestroad 12, 7766 MyTown, My Country

is visible and the node structure is hidden.

Question: How can I ensure that the node "Anne Charles" is visible and also the horizontal scrollbar is aligned to the left, which means that the node structure left from the text is still visible?

Best wishes
Michael

[Visual Basic .net 2005]
0
Comment
Question by:mp45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1600 total points
ID: 24035235
Use the SetScrollInfo() API like this:
Public Class Form1
 
    Private Const SB_VERT As Integer = 1
    Private Const SB_HORZ As Integer = 0
    Private Const SIF_PAGE As Integer = &H2
    Private Const SIF_POS As Integer = &H4
    Private Const SIF_RANGE As Integer = &H1
    Private Const SIF_TRACKPOS As Integer = &H10
    Private Const SIF_ALL As Integer = _
        (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)
 
    Private Structure SCROLLINFO
        Public cbSize As Integer
        Public fMask As Integer
        Public nMin As Integer
        Public nMax As Integer
        Public nPage As Integer
        Public nPos As Integer
        Public nTrackPos As Integer
    End Structure
 
    Private Declare Function SetScrollInfo Lib "user32" _
        (ByVal hWnd As IntPtr, ByVal n As Integer, _
        ByRef lpcScrollInfo As SCROLLINFO, ByVal bool As Boolean) As Integer
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.treeViewM.Nodes(0).Nodes(0).Nodes(0).EnsureVisible()
 
        Dim sci As SCROLLINFO
        sci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(sci)
        sci.fMask = SIF_ALL
        sci.nPos = 0 ' <--- this makes it go all the way to the left
        SetScrollInfo(treeViewM.Handle, SB_HORZ, sci, True)
    End Sub
 
End Class

Open in new window

0
 

Author Comment

by:mp45
ID: 24086528
thanks.

Does it mean there does not exist a solution within the .net-framework, e.g. a treeview method I just have not realized yet?

Michael
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24087803
No...I didn't see anyway to do it via built-in methods...
(hopefully I didn't miss it too!)
0
 

Author Comment

by:mp45
ID: 24088276
thanks a lot.
I've found this solution in addition:
http://www.codeproject.com/KB/tree/NoScrollingTree.aspx

Michael
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24088676
Kewl...so essentially the same approach but with a different API.  =)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question