|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Treeview doubleclick helpinto problems. My Treeview has just two levels of nodes: top-level and one child level. I want a doube-click on the Treeview to do one of two things: If the double-click was on a top-level node then the default action of exapnding/collapsing the node should be allowed as usual and with no further action. If the double-click was on a child-node then I want to be able to pick up the text of the child item that was clicked (ie the selected item). (And if the double-click was on neither then just ignore) The problem is how best to distinguish between the top- and child-level clicks. I'm obviously looking to place some code in the Treeview's doubleclick event but the eventargs of this event don't AFAICS return anything useful. Any pointers much appreciated. JGD You can include a key for each node, which can be any string you
choose. I did this in a project, which looked something like this: level-name-creationdate-uniqueid so every one was unique ( it is a key ). You can configure this however suits you. Tom John Dann wrote: Show quoteHide quote >I'm trying to implement a fairly simple Treeview procedure but running >into problems. > >My Treeview has just two levels of nodes: top-level and one child >level. I want a doube-click on the Treeview to do one of two things: > >If the double-click was on a top-level node then the default action of >exapnding/collapsing the node should be allowed as usual and with no >further action. > >If the double-click was on a child-node then I want to be able to pick >up the text of the child item that was clicked (ie the selected item). > >(And if the double-click was on neither then just ignore) > >The problem is how best to distinguish between the top- and >child-level clicks. > >I'm obviously looking to place some code in the Treeview's doubleclick >event but the eventargs of this event don't AFAICS return anything >useful. > >Any pointers much appreciated. > >JGD > > You could also maintain a collection that would contain just the root
nodes (add them to the collection when you populate the treeview nodes). Then you can do a quick if RootNodeCollection.Contains(...) test. Just my 2 cents Thanks, Seth Rowe John Dann wrote: Show quoteHide quote > I'm trying to implement a fairly simple Treeview procedure but running > into problems. > > My Treeview has just two levels of nodes: top-level and one child > level. I want a doube-click on the Treeview to do one of two things: > > If the double-click was on a top-level node then the default action of > exapnding/collapsing the node should be allowed as usual and with no > further action. > > If the double-click was on a child-node then I want to be able to pick > up the text of the child item that was clicked (ie the selected item). > > (And if the double-click was on neither then just ignore) > > The problem is how best to distinguish between the top- and > child-level clicks. > > I'm obviously looking to place some code in the Treeview's doubleclick > event but the eventargs of this event don't AFAICS return anything > useful. > > Any pointers much appreciated. > > JGD In the click event, you can check to see if the node passed to the event has
a parent or not...if not, then it's not a child node. -- Show quoteHide quoteDennis in Houston "John Dann" wrote: > I'm trying to implement a fairly simple Treeview procedure but running > into problems. > > My Treeview has just two levels of nodes: top-level and one child > level. I want a doube-click on the Treeview to do one of two things: > > If the double-click was on a top-level node then the default action of > exapnding/collapsing the node should be allowed as usual and with no > further action. > > If the double-click was on a child-node then I want to be able to pick > up the text of the child item that was clicked (ie the selected item). > > (And if the double-click was on neither then just ignore) > > The problem is how best to distinguish between the top- and > child-level clicks. > > I'm obviously looking to place some code in the Treeview's doubleclick > event but the eventargs of this event don't AFAICS return anything > useful. > > Any pointers much appreciated. > > JGD > John Dann wrote:
> I'm trying to implement a fairly simple Treeview procedure but running Root nodes don't have a Parent whereas Child nodes do.> into problems. My Treeview has just two levels of nodes: top-level > and one child level. > > The problem is how best to distinguish between the top- and > child-level clicks. Check the TreeView's SelectedNode property and then whether or not it's Parent property has any value. Sub tv_DoubleClick( ... ) Handles tv.DoubleClick If Not ( tv.SelectedNode Is Nothing ) Then If tv.SelectedNode.Parent Is Nothing Then ' Root Node Else ' Child Node (somewhere down the tree) End If Else ' Nothing at all selected End If End Sub You /might/ also need to put code into the MouseUp event to ensure that there is an item selected when the double-click event arrives. I can't remember if this happens automatically or not, but I've had to do this for context menus, so I thought I'd better throw it in : Sub tv_MouseUp( ... ) Handles tv.MouseUp Dim node as TreeNode _ tv.GetNodeAt( e.X, e.Y ) If Not ( node Is Nothing ) Then tv.SelectedNode = node End If End Sub If you take this model further, so that different nodes can perform different "actions", then you might consider adding customised TreeNodes to the Treeview and adding code into methods on these custom Treenodes, something like : Class BeepingNode Inherits TreeNode Public Sub New() MyBase.New() End Sub Public Sub Beep() Beep() End Sub End Class Then Sub tv_AfterSelect( ... ) Handles tv.AfterSelect If TypeOf e.Node Is BeepingNode Then DirectCast( e.Node, BeepingNode ).Beep() End If End Sub HTH, Phill W.
Why does activex control run 3x+ faster in vb5 than .net?
Format string in DataGrid TCP Transfer issues From VB Newbie: The editor is driving me nuts. Multiple TcpListeners on the same IP address To create an instance of class in VB2005 Help with Vb.net 2002 Update VB6 to VB.NET 2.0 Email Send Windows Service not starting automatically ATTN: Seth Rowe follow up to startup path posting |
|||||||||||||||||||||||