|
tech
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
TreeView multiple selectionsHi,
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,
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 ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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 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 ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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 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 ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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 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]"" wrote: Show quote > 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, 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 ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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,
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 ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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 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 ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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 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. Hi, Jeffrey:
I didn't question Control's event order in general, but here the events in both applications and Overrides On***() and our codes inside them when customized. Keep in mind the context is that we are customizing TreeView so we put codes in Overrides On***() events. Let's see an event order: OnNodeMouseClick() --> .NodeMouseClick() --> OnAfterSelect() --> ..AfterSelect(). The order is by design. It looks ok. But after we customized it, we have codes in OnAfterSelect(). Now we can see application's .NodeMouseClick() is run before Overrides OnAfterSelect(). In other word, app's codes run before Control's customizing codes. But I expect all customizing codes are run before any app's codes. So app's codes can have the correct outcome from customizing codes. But that's not the case. That's what I mean by "mingle". Thanks. Li ""Jeffrey Tan[MSFT]"" wrote: Show quote > 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. > > > Hi Li,
Thanks for your detailed explanation! Ok, I see your key concern now. However, there is no design spec or document stating that "all customizing codes should run before any app's codes". There is no guarantee for this, so you should not take this as assumption. Actually, events are not magic; it is always the OnXXX method internally fires the XXX event. So the control events order are always OnXXX->XXX->OnYYY->YYY. You'd better use this design order instead of that assumption. If you wanted that your code is fired very early, maybe you should place them in the constructor of the control class. 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 message. Basically we share the same point now. Just want to make some side notes: (Feel free to not continue this discussion if you don't want to) 1) Design order: OnXXX->XXX->OnYYY->YYY. The problem is when we customize a control, we don't know XXX or YYY. We implement OnXXX and OnYYY. Then we give this customized control to other developers. They will use it in various app and implement different XXX. They don't care what is in OnYYY. We don't want them to check OnYYY before they design their XXX. And in some cases they can't even see the OnYYY (it is by a ..dll). 2) Place them in the constructor of the control class. In some cases we still need an event to implement something. For instance, we need a click event to implement multiple selection. If users do nothing, nothing happens. In this case a constructor will not do. 3) My thinking is that basically it is not safe to use On*** events to customize a control. You never know how other developers fire their app events. Just like what you said, the design should base on OnXXX->XXX->OnYYY->YYY. But when we base on XXX/YYY, it is not a customized control. It is a case by case design. We may just better off move OnXXX's codes to XXX to make it more straightforward. I didn't say we cannot do it in an app. What I said is we can't customize it in this way. Thanks. Li ""Jeffrey Tan[MSFT]"" wrote: Show quote > Hi Li, > > Thanks for your detailed explanation! > > Ok, I see your key concern now. However, there is no design spec or > document stating that "all customizing codes should run before any app's > codes". There is no guarantee for this, so you should not take this as > assumption. Actually, events are not magic; it is always the OnXXX method > internally fires the XXX event. So the control events order are always > OnXXX->XXX->OnYYY->YYY. You'd better use this design order instead of that > assumption. > > If you wanted that your code is fired very early, maybe you should place > them in the constructor of the control class. 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,
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/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. |
|||||||||||||||||||||||