468,272 Members | 2,070 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

TreeView multiple selections

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

Oct 1 '07 #1
18 14825
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/f...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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 2 '07 #2
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 5 '07 #3
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

""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 5 '07 #4
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 8 '07 #5
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

""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 12 '07 #6
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 15 '07 #7
Thanks!

""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 15 '07 #8
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

""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 16 '07 #9
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 17 '07 #10
Thanks!
""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 17 '07 #11
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]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 17 '07 #12
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 18 '07 #13
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 22 '07 #14
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 25 '07 #15
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

""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 26 '07 #16
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 29 '07 #17
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

""Jeffrey Tan[MSFT]"" wrote:
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 29 '07 #18
Hi Li,

Thanks for your feedback.

Below are some options from me:
You should treat OnXXX like an event. We seldom use the XXX events in the
customized control, they are used for the application developer instead of
control author; as customize control author we should use OnXXX for event
processing.

Yes, I agree that application developers know nothing about the OnXXX(they
are protected methods). Application developers should use XXX events for
processing. But I did not see any problem here. As the customize control
author, the advantage of using OnXXX method is that your code can choose to
execute before and after this XXX event, although there is no guarantee
that OnXXX will execute before all XXX, YYY, ZZZ events.

I am not sure why do you say "it is not safe to use On*** events to
customize a control. You never know how other developers fire their app
events". Actually it is the OnXXX fires XXX event, not application
developers:
OnXXX(Argument e)
{
//customize control author code that executes before XXX event
if(XXX!=null)
{
XXX(e); //fires XXX event
}
//customize control author code that executes after XXX event
}

Does this make sense to you?

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 1 '07 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by theoryboy | last post: by
2 posts views Thread by Craig B. | last post: by
2 posts views Thread by Steffen Loringer | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.