-
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
-
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
-
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
-
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...
-
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...
-
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
-
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
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks