Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Đó là bởi vì FileWatcher các vụ cháy các sự kiện trên một chủ đề, chứ không phải các chủ đề đó là kiểm soát ứng dụng của bạn. Để ngăn chặn một cuộc xung đột, hãy xem xét mã được hiển thị trong các dự án FileWatcher (bao gồm các mẫu mã), trong đó sử dụng Control.Invoke () | Dim nodeParent nodeChild As TreeNode Dim rowParent rowChild As DataRow For Each rowParent In dsNorthwind.Tables Customers .Rows Add the customer node. nodeParent treeDB.Nodes.Add rowParent CompanyName Store the disconnected customer information for later. nodeParent.Tag rowParent For Each rowChild In rowParent.GetChildRows relCustomersOrders Add the child order node. nodeChild nodeParent.Nodes.Add rowChild OrderID Store the disconnected order information for later. nodeChild.Tag rowChild Next Next As an added enhancement this code stores a reference to the associated DataRow object in the Tag property of each TreeNode. When the node is clicked all the information is retrieved from the DataRow and then displayed in the adjacent text box. This is one of the advantages of disconnected data objects You can keep them around for as long as you want. NOTE You might remember the Tag property from Visual Basic 6 where it could be used to store a string of information for your own personal use. The Tag property in VB 2005 is similar except you can store any type of object in it. Private Sub treeDB_AfterSelect ByVal sender As System.Object _ ByVal e As System.Windows.Forms.TreeViewEventArgs _ Handles treeDB.AfterSelect Clear the textbox. txtInfo.Text Dim row As DataRow CType e.Node.Tag DataRow Fill the textbox with information from every field. Dim Field As Object For Each Field In row.ItemArray txtInfo.Text Field.ToString vbNewLine Next End Sub This sample program featured in the chapter examples as the RelationalTreeView project and shown in Figure 10-10 is also a good demonstration of docking at work. To make sure all the controls stay where they should and to allow the user to change the relative screen area given to the TreeView and text box a SplitContainer control is used along with an additional Panel along the bottom. 340 Chapter 10 Figure 10-10 An advanced example of relational data Using a DataSet Object to Update Data The DataSet object stores additional .