TreeView multiple selections

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Is there a way for TreeView to have multiple selections? But I am not
talking about its checked boxes.

I want a way similar to ListView with MultiSelect = True. So I can use
[Ctrl] or [Shift] key and click to make multiple selections. Then when I
simply click one item, all previous selections are gone.

Thanks in advance.

Li
 
Hi Li,

Yes, the .Net TreeView control does not support multiple selection by
default. We normally enable checkbox for all the TreeNodes, so that we may
use CheckBox to indicate the multiple selection. However, if you really
wanted to get the true multiple selection function in TreeView, you have to
customize TreeView control. The articles below provide the extended version
of TreeView with multiple selection function:
"C# TreeView with multiple selection"
http://www.codeproject.com/cs/miscctrl/treeviewms.asp
"Multi-Select TreeView"
http://windowsclient.net/downloads/folders/applications/entry1273.aspx
"Multi-Select TreeView Control in C#"
http://www.codeproject.com/cs/miscctrl/mwcontrols.asp

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Li,

Have you reviewed my reply to you? Does it make sense to you? If you still
need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

Thanks a lot for the help!
I have read your response but haven't got a chance to read the articles and
try them out. I will do that after I finish my current work.

Thanks again.

Li
 
Hi Li,

Thank you for the confirmation.

Ok, if you need any further help, please feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

Now I am testing the first article: "C# TreeView with multiple selection".
The codes look ok. But I encounter a problem from TreeView.

After I click to select a node, then I click it again, it will not trigger
OnBeforeSelect or OnAfterSelect.
But if I click other nodes, i.e., not the last selected node, both of them
will be triggered.

Is TreeView designed by this way? If so, how to workaround to catch
selecting twice the node while pressing CTRL to un-select it?

By the way, I am using VB.net, not C#. But I think here is a raising event
issue.

Thanks in advance.

Li
 
Hi Li,

Thanks for your feedback.

Yes, this behavior also occurs in build-in TreeView control and is by
design. To workaround this behavior, you may handle the TreeView.Click
event. In this event, you may use check the mouse position to determine
which node is clicked. The code below demonstrates this logic:

Private Sub TreeView1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TreeView1.Click
Dim pt As Point = Me.TreeView1.PointToClient(New
Point(Control.MousePosition.X, Control.MousePosition.Y))
Dim tn As TreeNode = Me.TreeView1.GetNodeAt(pt)
If Not (tn Is Nothing) Then
'Perform your logic based on the clicked node
End If
End Sub

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

Look like for TreeView, if I click a node (selected), I can't set its
BackColor or ForeColor in codes. It is always painted as Highlighted.

Is it by designed? If so, how can I re-paint it to normal when selecting
twice with [CTRL]?

I suspect Microsoft has made changes to TreeView so 2005 version is
different from older version (2002) the article's codes run on.

Thanks.

Li
 
Hi Li,

Thanks for your feedback.

Yes, .Net TreeView control encapsulates Win32 native tree view control. All
these behaviors are by design by the win32 tree view control.

To customize the hightlighted node colors, we may use custom-draw to get it
done. Fortunately, .Net2.0 has added the build-in support for custom-draw.

To use custom draw for your task, you may set TreeView.DrawMode to
OwnerDrawText and handle TreeView.DrawNode event. Then, in this event, you
may check the status of each node and paints its text and background
rectangle based on your requirement. The code snippet demonstrates this
logic:

Private tagFont As New Font("Helvetica", 8, FontStyle.Bold)

Private Sub TreeView1_DrawNode(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DrawTreeNodeEventArgs) Handles TreeView1.DrawNode
' Draw the background and node text for a selected node.
If (e.State And TreeNodeStates.Selected) <> 0 Then

' Draw the background of the selected node. The NodeBounds
' method makes the highlight rectangle large enough to
' include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node))

' Retrieve the node font. If the node font has not been set,
' use the TreeView font.
Dim nodeFont As Font = e.Node.NodeFont
If nodeFont Is Nothing Then
nodeFont = CType(sender, TreeView).Font
End If

' Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, _
e.Bounds.Left - 2, e.Bounds.Top)

' Use the default background and node text.
Else
e.DrawDefault = True
End If

' If a node tag is present, draw its string representation
' to the right of the label text.
If (e.Node.Tag IsNot Nothing) Then
e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, _
Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
End If

' If the node has focus, draw the focus rectangle large, making
' it large enough to include the text of the node tag, if present.
If (e.State And TreeNodeStates.Focused) <> 0 Then
Dim focusPen As New Pen(Color.Black)
Try
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
Dim focusBounds As Rectangle = NodeBounds(e.Node)
focusBounds.Size = New Size(focusBounds.Width - 1, _
focusBounds.Height - 1)
e.Graphics.DrawRectangle(focusPen, focusBounds)
Finally
focusPen.Dispose()
End Try
End If
End Sub

Private Function NodeBounds(ByVal node As TreeNode) As Rectangle

' Set the return value to the normal node bounds.
Dim bounds As Rectangle = node.Bounds
If (node.Tag IsNot Nothing) Then

' Retrieve a Graphics object from the TreeView handle
' and use it to calculate the display width of the tag.
Dim g As Graphics = Me.TreeView1.CreateGraphics()
Dim tagWidth As Integer = CInt(g.MeasureString( _
node.Tag.ToString(), tagFont).Width) + 6

' Adjust the node bounds using the calculated value.
bounds.Offset(tagWidth \ 2, 0)
bounds = Rectangle.Inflate(bounds, tagWidth \ 2, 0)
g.Dispose()
End If
Return bounds
End Function 'NodeBounds

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks!


"Jeffrey Tan[MSFT]" said:
Hi Li,

Thanks for your feedback.

Yes, .Net TreeView control encapsulates Win32 native tree view control. All
these behaviors are by design by the win32 tree view control.

To customize the hightlighted node colors, we may use custom-draw to get it
done. Fortunately, .Net2.0 has added the build-in support for custom-draw.

To use custom draw for your task, you may set TreeView.DrawMode to
OwnerDrawText and handle TreeView.DrawNode event. Then, in this event, you
may check the status of each node and paints its text and background
rectangle based on your requirement. The code snippet demonstrates this
logic:

Private tagFont As New Font("Helvetica", 8, FontStyle.Bold)

Private Sub TreeView1_DrawNode(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DrawTreeNodeEventArgs) Handles TreeView1.DrawNode
' Draw the background and node text for a selected node.
If (e.State And TreeNodeStates.Selected) <> 0 Then

' Draw the background of the selected node. The NodeBounds
' method makes the highlight rectangle large enough to
' include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node))

' Retrieve the node font. If the node font has not been set,
' use the TreeView font.
Dim nodeFont As Font = e.Node.NodeFont
If nodeFont Is Nothing Then
nodeFont = CType(sender, TreeView).Font
End If

' Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, _
e.Bounds.Left - 2, e.Bounds.Top)

' Use the default background and node text.
Else
e.DrawDefault = True
End If

' If a node tag is present, draw its string representation
' to the right of the label text.
If (e.Node.Tag IsNot Nothing) Then
e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, _
Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
End If

' If the node has focus, draw the focus rectangle large, making
' it large enough to include the text of the node tag, if present.
If (e.State And TreeNodeStates.Focused) <> 0 Then
Dim focusPen As New Pen(Color.Black)
Try
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
Dim focusBounds As Rectangle = NodeBounds(e.Node)
focusBounds.Size = New Size(focusBounds.Width - 1, _
focusBounds.Height - 1)
e.Graphics.DrawRectangle(focusPen, focusBounds)
Finally
focusPen.Dispose()
End Try
End If
End Sub

Private Function NodeBounds(ByVal node As TreeNode) As Rectangle

' Set the return value to the normal node bounds.
Dim bounds As Rectangle = node.Bounds
If (node.Tag IsNot Nothing) Then

' Retrieve a Graphics object from the TreeView handle
' and use it to calculate the display width of the tag.
Dim g As Graphics = Me.TreeView1.CreateGraphics()
Dim tagWidth As Integer = CInt(g.MeasureString( _
node.Tag.ToString(), tagFont).Width) + 6

' Adjust the node bounds using the calculated value.
bounds.Offset(tagWidth \ 2, 0)
bounds = Rectangle.Inflate(bounds, tagWidth \ 2, 0)
g.Dispose()
End If
Return bounds
End Function 'NodeBounds

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

If I click to select a node, then click the node again, it will not trigger
DrawNode() event. I guess it is by design.

But with this behavior I can't draw a node to normal after selecting twice
with [CTRL]. It does trigger Click() event but Click() doesn't have
DrawNode()'s e (DrawTreeNodeEventArgs) to use to do the drawing.

Thanks.

Li

"Jeffrey Tan[MSFT]" said:
Hi Li,

Thanks for your feedback.

Yes, .Net TreeView control encapsulates Win32 native tree view control. All
these behaviors are by design by the win32 tree view control.

To customize the hightlighted node colors, we may use custom-draw to get it
done. Fortunately, .Net2.0 has added the build-in support for custom-draw.

To use custom draw for your task, you may set TreeView.DrawMode to
OwnerDrawText and handle TreeView.DrawNode event. Then, in this event, you
may check the status of each node and paints its text and background
rectangle based on your requirement. The code snippet demonstrates this
logic:

Private tagFont As New Font("Helvetica", 8, FontStyle.Bold)

Private Sub TreeView1_DrawNode(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.DrawTreeNodeEventArgs) Handles TreeView1.DrawNode
' Draw the background and node text for a selected node.
If (e.State And TreeNodeStates.Selected) <> 0 Then

' Draw the background of the selected node. The NodeBounds
' method makes the highlight rectangle large enough to
' include the text of a node tag, if one is present.
e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node))

' Retrieve the node font. If the node font has not been set,
' use the TreeView font.
Dim nodeFont As Font = e.Node.NodeFont
If nodeFont Is Nothing Then
nodeFont = CType(sender, TreeView).Font
End If

' Draw the node text.
e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, _
e.Bounds.Left - 2, e.Bounds.Top)

' Use the default background and node text.
Else
e.DrawDefault = True
End If

' If a node tag is present, draw its string representation
' to the right of the label text.
If (e.Node.Tag IsNot Nothing) Then
e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, _
Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
End If

' If the node has focus, draw the focus rectangle large, making
' it large enough to include the text of the node tag, if present.
If (e.State And TreeNodeStates.Focused) <> 0 Then
Dim focusPen As New Pen(Color.Black)
Try
focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
Dim focusBounds As Rectangle = NodeBounds(e.Node)
focusBounds.Size = New Size(focusBounds.Width - 1, _
focusBounds.Height - 1)
e.Graphics.DrawRectangle(focusPen, focusBounds)
Finally
focusPen.Dispose()
End Try
End If
End Sub

Private Function NodeBounds(ByVal node As TreeNode) As Rectangle

' Set the return value to the normal node bounds.
Dim bounds As Rectangle = node.Bounds
If (node.Tag IsNot Nothing) Then

' Retrieve a Graphics object from the TreeView handle
' and use it to calculate the display width of the tag.
Dim g As Graphics = Me.TreeView1.CreateGraphics()
Dim tagWidth As Integer = CInt(g.MeasureString( _
node.Tag.ToString(), tagFont).Width) + 6

' Adjust the node bounds using the calculated value.
bounds.Offset(tagWidth \ 2, 0)
bounds = Rectangle.Inflate(bounds, tagWidth \ 2, 0)
g.Dispose()
End If
Return bounds
End Function 'NodeBounds

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Li,

Thanks for your feedback.

You may use the logic like this:
In the event while detecting selecting twice with [CTRL], you may set a
field flag from false to true. Then call the TreeView.Invalidate() method
to redraw the entire area of TreeView control. Then the TreeView.DrawNode
event will fire again. In this event, you may check the field flag and draw
different effect based on the flag value(true or false).

If you still have anything unclear, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Li,

Have you reviewed my last reply to you? Does this code logic work for you?
If you still need any help or have any concern, please feel free to tell
me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

Thanks for your help.
Technically it works. But it is not a customized TreeView control anymore.
What I means is that I implemented those Overrides OnNodeMouseClick(),
OnDrawNode(), OnAfterSelect(), etc.; add this customized control to a simple
form; I can do multiple selections.

But if I add it to my application GUI and create its .NodeMouseClick(),
etc., events, these app events mingle with those Overrides On*** events. I
can't control the order of these events and they are fired everywhere. Some
of app events come before Overrides On*** events. So the result is not
correct.

Now I am applying these codes directly to my app's regular TreeView. If I
have 2 TreeViews, I have to duplicate the codes.

I assume this is the best we can do.

Thanks.

Li
 
Hi Li,

Thanks for your feedback.

As far as I know, if we can get the TreeView working by handling it various
events, we should be able to get it working by inheriting from it and
customizing it. I can not understand your statement of "these app events
mingle with those Overrides On*** events". Can you provide a little sample
project to help me reproduce this problem? Then, I will help you to work it
out withtout duplicating code.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

Here is what I did:

I created a User Control MyTreeView to inherit TreeView.
I overrided OnNodeMouseClick() to update selected nodes collection.
Inside I need to first call MyBase.OnNodeMouseClick(e).

In my application, I added MyTreeView to a form. In codes I created
MyTreeView.NodeMouseClick() event to check which nodes are selected and do
something.

Now when I click, it calls OnNodeMouseClick(), which run
MyBase.OnNodeMouseClick(e) first. It fires MyTreeView.NodeMouseClick()
immediately.

But at this time the codes after MyBase.OnNodeMouseClick(e) in
OnNodeMouseClick() hasn't been run yet. So selected nodes collection hasn't
been updated. MyTreeView.NodeMouseClick() uses the old collection so it is
not correct.

So I have to move all codes in OnNodeMouseClick() to my application's
MyTreeView.NodeMouseClick() to put them together to control the logic flow.

Is it ok if I don't call MyBase.OnNodeMouseClick(e)?

Thanks.

Li
 
Hi Li,

Thanks for your feedback.

MyBase.OnNodeMouseClick(e) internally fires the NodeMouseClick event, so
you should call it while overriding OnNodeMouseClick() method.

Why not calling the MyBase.OnNodeMouseClick(e) after all your code logic in
OnNodeMouseClick()? That is: why not calling MyBase.OnNodeMouseClick(e) at
the end of overriding OnNodeMouseClick() instead of calling it first?

By doing this change, your code of update selected nodes collection
executed first and then MyBase.OnNodeMouseClick(e) which fires
NodeMouseClick event. So your code in NodeMouseClick event will see the
updated selected nodes collection correctly.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi, Jeffrey:

Thanks for your suggestions.

This may work in some specific scenarios. But my codes call Invalidate(),
which fire OnDrawNode(). If app uses DrawNode() event, I see a situation that
OnNodeMouseClick() --> OnDrawNode() --> .DrawNode() --> (Back to
OnNodeMouseClick()) MyBase.OnNodeMouseClick(e) --> .NodeMouseClick().

In other word, I still see these events mingle together. I may also use
other events like AfterSelect() in both app and customized TreeView.

Yes, by careful design, it may work in expected logic. But when develop
application logic, we need to check customized TreeView's events logic and
design their logic together. So in some cases it may be more straight forward
just to move the codes together to app.

Thanks.

Li
 
Hi Li,

Thanks for your feedback.

Why do you believe that the events order is mingled? I think they are well
designed as expected. Invalidate() will definitely cause OnDrawNode() which
internally fires DrawNode event. Their orders are all expected not
randomized.

Whether you should use one event or another depends on your code logic. My
suggestion is understanding why one method/event is called before another
method/event. Then you should understand which method/event you should use.

Anyway, if I have misunderstood your problem, please feel free to tell me,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top