tailieunhanh - Bind Data to ComboBox and DataGrid Controls

1,8 Bind dữ liệu vào ComboBox và DataGrid Controls Đôi khi bạn có thể muốn sử dụng điều khiển ComboBox thay vì một điều khiển ListBox để hiển thị một danh sách các lựa chọn. Bạn cũng có thể muốn hiển thị thông tin trong một phong cách lưới dựa trên các mục chọn trong hộp kết hợp. d kỹ thuật mã hóa mà bạn đã sử dụng cho điều khiển ListBox | Bind Data to ComboBox and DataGrid Controls Sometimes you might want to use a ComboBox control instead of a ListBox control to display a list of choices. You also might want to display information in a grid style based on the item chosen in that combo box. This How-To describes how to bind data to both ComboBox and DataGrid controls. Instead of using a ListBox control to display customers you would like to use a ComboBox control to display them. After you choose a customer you would like to display information about the orders that belong to that customer. How do you bind data to the ComboBox and then bind the DataGrid control as well Technique To bind both the ComboBox and the DataGrid controls you will use the same properties and coding techniques that you have used for the ListBox control. You will first create DataAdapter and DataSet controls to which to set the DataSource properties. The DataAdapter for the DataGrid will include a parameter that will use the value selected in the ComboBox control. You will set the DataSource properties of the controls to the DataSet created. That is all you really have to set for the DataGrid control. For the ComboBox control you will also set the ValueMember and DisplayMember properties. You will then add code to fill the DataSet control to which the DataSource property is set for the ComboBox control. Finally you will create a subroutine to store the selected value in the ComboBox in the DataAdapter that was created for filling the DataSet on which the DataGrid control is based. After the user has selected a value in the ComboBox that contains the customers the DataGrid control displays the orders for that customer as can be seen in Figure . Figure . Users can display the header information for customer orders using these two controls. Steps You will be starting with a fresh form. 1. Add a new Windows Form called frmHowTo1_8. 2. Add the OleDbDataAdapter and DataSet controls with the properties set forth in Table

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.