Selecting treeview nodes with API problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Selecting treeview nodes with API problem

  1. #1
    Crispin Guest

    Selecting treeview nodes with API problem


    I am trying to change the selection of a treeview node using the following
    code (I know theres no error checking or function return)

    Public Function Treeview_SelectNode(TreeViewHwnd As Long, hItem As Long)
    As Long
    Dim newstate As Long
    Dim itm As Long
    Dim tvi As TVITEM
    With tvi
    .hItem = hItem
    .mask = TVIF_STATE
    .stateMask = TVIS_SELECTED
    newstate = SendMessage(TreeViewHwnd, TVM_GETITEMA, 0, tvi)
    .state = .state And TVIS_SELECTED
    End With
    newstate = SendMessage(TreeViewHwnd, TVM_SETITEMA, 0, tvi)
    End Function

    it won't change the selection and I can't work out why...do I need to subclass
    the treeview and discard some messages elsewhere? any help is most appreciated.

    Thanks

    Crispin

  2. #2
    Mattias Sjögren Guest

    Re: Selecting treeview nodes with API problem

    Crispin,

    > .state = .state And TVIS_SELECTED


    The error in your code is here. It should be

    ..state = .state Or TVIS_SELECTED


    But it's even easier if you use the TVM_SELECTITEM message.


    Matt

    ====================================
    Mattias Sjögren - mattias @ mvps.org
    http://www.msjogren.net/dotnet/

    CodeHound - The Software Developer's Search Engine
    http://www.codehound.com

  3. #3
    Mattias Sjögren Guest

    Re: Selecting treeview nodes with API problem

    Crispin,

    > .state = .state And TVIS_SELECTED


    The error in your code is here. It should be

    ..state = .state Or TVIS_SELECTED


    But it's even easier if you use the TVM_SELECTITEM message.


    Matt

    ====================================
    Mattias Sjögren - mattias @ mvps.org
    http://www.msjogren.net/dotnet/

    CodeHound - The Software Developer's Search Engine
    http://www.codehound.com

  4. #4
    Crispin Guest

    Re: Selecting treeview nodes with API problem


    Thanks for your help Mattias, I moved onto your other suggestion, and I still
    can't get it to work:

    Please excuse the absolute reference to the treeview control, it's just for
    testing...
    (I have made sure that the hItem exists)
    it returns false every time, I tried following the prototypes in the platform
    SDK, but with no luck...

    'TVM_SELECTITEM shows up as being 4363
    'TVGN_CARET shows up as being 9

    Public Function SelNode(hItem As Long) As Boolean
    SelNode = SendMessage(Form1.TreeView1.hWnd, TVM_SELECTITEM, TVGN_CARET,
    hItem)
    End Function

    thanks again for any help...

  5. #5
    Crispin Guest

    Re: Selecting treeview nodes with API problem


    Thanks for your help Mattias, I moved onto your other suggestion, and I still
    can't get it to work:

    Please excuse the absolute reference to the treeview control, it's just for
    testing...
    (I have made sure that the hItem exists)
    it returns false every time, I tried following the prototypes in the platform
    SDK, but with no luck...

    'TVM_SELECTITEM shows up as being 4363
    'TVGN_CARET shows up as being 9

    Public Function SelNode(hItem As Long) As Boolean
    SelNode = SendMessage(Form1.TreeView1.hWnd, TVM_SELECTITEM, TVGN_CARET,
    hItem)
    End Function

    thanks again for any help...

  6. #6
    Mattias Sjögren Guest

    Re: Selecting treeview nodes with API problem

    Crispin,

    Try

    > SelNode = SendMessage(Form1.TreeView1.hWnd, TVM_SELECTITEM, TVGN_CARET, ByVal hItem)


    ^^^^^


    Matt

    ====================================
    Mattias Sjögren - mattias @ mvps.org

  7. #7
    Mattias Sjögren Guest

    Re: Selecting treeview nodes with API problem

    Crispin,

    Try

    > SelNode = SendMessage(Form1.TreeView1.hWnd, TVM_SELECTITEM, TVGN_CARET, ByVal hItem)


    ^^^^^


    Matt

    ====================================
    Mattias Sjögren - mattias @ mvps.org

  8. #8
    Crispin Guest

    Re: Selecting treeview nodes with API problem


    Thanks Matt,

    Still didn't work though ???? Somoneone should slap me for sending things
    ByRef like that (how stupid can you get???) I think I'm gonna go to Brad
    M's site and grab some Treeview samples to see what i'm doing wrong - if
    you want some source to see what i'm trying to do then let me know, but thanks
    for all your help anyway!!!

    Crispin

  9. #9
    Crispin Guest

    Re: Selecting treeview nodes with API problem


    Thanks Matt,

    Still didn't work though ???? Somoneone should slap me for sending things
    ByRef like that (how stupid can you get???) I think I'm gonna go to Brad
    M's site and grab some Treeview samples to see what i'm doing wrong - if
    you want some source to see what i'm trying to do then let me know, but thanks
    for all your help anyway!!!

    Crispin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center