A problem with using. Net framewrok 1.1 system. Windows. Forms. Treeview

Source: Internet
Author: User
A problem was found when Treeview was used last week. Assume that the Treeview contains multiple root nodes and child nodes. For example, you have registered Treeview In the instance constructor or before using it for the first time. afterselect event, this. treeview1.afterselect + = new system. windows. forms. treevieweventhandler (this. treeviewmediaafterselect); event processing is as follows: Program Used to calculate the number of event programs running. Private int I = 0; private void treeview1_afterselect (Object sender, system. windows. forms. treevieweventargs e) {I ++; this. label1.text = I. tostring ();} (1 ). when you click [Node 1] for the first time, I = 1; this is no problem. If you click another node for the first time, such as [Node 2] or [node 1.1], then I = 2, that is, two afterselect events are generated when a node is selected. Code Perform one-step debugging to find the E. node. the text value is "Node 1", that is, the first afterselect event is generated by [Node 1] (this node is not clicked here), and the second event is the expected event. (2 ). to solve this problem, I tried to click the expand/collapse icon (+/-) in front of the node for the first time, no matter whether the clicked node is the first root node or not, all events are executed, which is equivalent to selecting the first root node. This is also true when this. treeview1.select () is called for the first time. For (1), I tested it on. NET Framework 2.0 beta2 and no two events occurred. Is this a bug? For (2) I just want to remind myself that the afterselect event will also be triggered when nodes are not directly selected. The test results in. NET Framework 2.0 beta2 are the same.

If you want to write highly efficient programs, I think it is a matter of consideration to trigger repeated events. For the above phenomenon, assume that a Treeview is placed on the left of the form to indicate the directory, and a DataGrid on the right to list the products corresponding to the directory based on the selection on the left, is it annoying to trigger two consecutive events, especially when the data volume is large.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.