Đang chuẩn bị liên kết để tải về tài liệu:
Visual Basic .NET at Work Building 10 Enterprise Projects phần 6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Cách tốt hơn để kết hợp các hình thức này vào chương trình của bạn là để xây dựng một thư viện lớp có chứa chúng. Không biết bạn có thể làm điều đó, bạn có? WinForms chỉ là các lớp học như bất cứ điều gì khác Bạn sẽ phải làm điều đó thông qua tài sản hoặc trong mã. | 238 Project 6 And here s the event trap for the ButtonColumn that gets us there Private Sub dgUsers_ItemCommand ByVal source As Object _ ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs _ Handles dgUsers.ItemCommand If e.CommandName EditUser Then Dim li As ListItem pnGrid.Visible False pnDetail.Visible True txtUserID.Text e.Item.Cells 0 .Text txtFirstName.Text e.Item.Cells 2 .Text txtLastName.Text e.Item.Cells 3 .Text txtUserEmail.Text e.Item.Cells 4 .Text BindDepartmentList For Each li In dlDepartment.Items If li.Value e.Item.Cells 6 .Text Then li.Selected True Exit For End If Next End If End Sub Let s first pick apart the method footprint. This is similar to the event trap footprint we ve worked with so far but the second parameter is not of type EventArgs. In this case it s DataGridCommandEventArgs. This is a class that inherits from and extends EventArgs. The inheritance provides type and functional support for all the portions of the Framework that deal with post backs generically. The extension allows the data grid to add some additional information to the type that is specific to the event it is raising. This is like COM object which supports more than one interface but it s even better than that because this extended type has the same interface as the original EventArgs class and all of the functionality as well. This means that when the creator of the data grid control needed the built-in functionality of the EventArgs class they got it free and had only to add a couple properties to create the additional functionality. The other difference in the footprint is the addition of the Handles keyword at the end. This is one way to set up an event trap in the .NET Framework. When the data grid control raises this event via a post back the Framework knows automatically to call this routine to handle the event because quite simply we ve told the Framework as much by saying it handles the ItemCommand event of the dgUsers DataGrid control. We ll take a