Thông tin tài liệu:
Làm việc với Danh sách Multi-Chọn Data-Bound Boxes Sử dụng Windows Forms Nó được phổ biến để có giao sản phẩm cho chủng loại, đó là một mối quan hệ một-nhiều. Đôi khi bạn muốn có thể làm điều này trong một thời trang phần nào số lượng lớn
Nội dung trích xuất từ tài liệu:
Work with Data-Bound Multi-Select List Boxes Using Windows Forms It is common to have to assign8.1 Work with Data-Bound Multi-Select List Boxes Using Windows FormsIt is common to have to assign products to categories, which is a one-to-manyrelationship. Sometimes you want to be able to do this in a somewhat bulk fashion. Oneof the methods that works well is using the ListBox control. Using the ListBox controlfor single selections is no big deal, but when it comes to using it in a multi-select method,it starts getting trickier. This How-To shows you how to create an intuitive interface forassigning products to categories using a couple of multi-select list boxes on a WindowsForm.You can assign a category to each product, but you would like to have a method ofmaintaining all the products for a category at one time. How do you take advantage of amulti-select list box to perform this task?TechniqueUsing the ListBox control in regular single selection mode is as straightforward in .NETas in prior versions of Visual Basic. The same can be said in the case of using the multi-select mode of list boxes. It is as confusing in .NET as it was in prior versions.Using the ListBox control in single entry mode is pretty straightforward. You just need touse the SelectedItem property with the index of 0. However, if you want to use theListBox control in multi-select mode, then you must perform some more work and accesssome other properties (see Table 8.1). Table 8.1. Properties Having to Do with Multi-Selection on ListBox Controls (In Order of Use in This How-Tos Steps)Property/Object DescriptionSelectionMode Property of the ListBox control. The settings for this are None, One, MultiSimple, or MultiExtended.SelectedIndices A collection of the ListBox control, this returns the indices(index) (location in the list) of all the selected items.SelectedIndices.Count Property of the ListBox control. A count of the number of items selected in the list box.DataRowView Object type that the data provider provides.Items (index) A collection of the ListBox control. Returns a DataRowView type object. If you have multiple columns, they are also returned in the DataRowView object.StepsOpen and run the VB.NET -Chapter 8 solution. From the main Windows Form, click onthe command button with the caption How-To 8.1. You will then see the form displayedin Figure 8.2.Figure 8.2. This form uses controls bound at runtime and takes advantage of multi- select list boxes.When the form loads, you will see the Beverages category chosen in the top combo box.The Selected and Unselected Products ListBox controls are filled in with the appropriateproducts. If you click on a product in the Unselected Products list box and then click onthe arrow button pointing to the right (>), then the item is moved to the Selected Productslist box. If you select items in the Selected Products list box and click on the arrow buttonpointing to the left (1. Create a Windows Form. Then place the controls shown in Figure 8.2 with the following properties set in Table 8.2. Table 8.2. Label, ComboBox, ListBox, and Command Button Control Property SettingsObject Property SettingLabel Text CategoryComboBox Name cboCategoriesLabel Text Unselected ProductsListBox Name lstUnSelected SelectionMode MultiSimpleLabel Text Selected ProductsListBox Name lstSelected SelectionMode MultiSimpleCommand Button Name btnSelect Text >Command Button Name btnUnSelect Text
Tài liệu được xem nhiều:
3373
1
0
9 trang
3019
44
0
26 trang
2144
3
0
7 trang
1978
20
0
18 trang
1684
15
0
79 trang
1674
0
0
267 trang
1603
21
0
8 trang
1545
24
0
3 trang
1528
4
0
80 trang
1501
8
0
99 trang
1492
49
0
1 trang
1386
25
0
69 trang