|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Clearing A List BoxIts time to load new items into a list boxdo you really have to clear the old items out one at a time with RemoveItem? You can use the Clear method to clear a list box. Nothing could be easier (so be carefultheres no undelete function here!). You just use clear like this: List.Clear. Heres how that looks in code; in this case, were clearing a list box, List1, when the user clicks a command button:
Private Sub Command1_Click()
List1.Clear
End Sub
Creating Simple Combo Boxes, Drop-Down Combo Boxes, And Drop-Down List Combo BoxesCombo boxes are those controls that usually display a text box and a drop-down list. In fact, you might think there is only one kind of combo box, but there are really three types, and you select which type you want with the combo boxs Style property. The default type of combo box is probably what you think of when you think of combo boxes, because, as mentioned, it is made up of a text box and a drop-down list. However, you can also have combo boxes where the list doesnt drop down (the list is always open, and you have to make sure to provide space for it when you add the combo box to your form) and combo boxes where the user can only select from the list. Here are the settings for the combo box Style property:
Adding Items To A Combo BoxYouve added a new combo box to your program, and it looks great. When you run it, however, all you see is Combo1 in it. How do you add items to your combo box? A combo box is a combination of a text box and a list box, so at design time, you can change the text in the text box part by changing the Text property. You change the items in the list box part with the List property (this item opens a drop-down list when you click it in the Properties window) at design time. At runtime, you can add items to a combo box using the AddItem() method, which adds items to the list box part. You can also add items to the list box using the List property, which is an indexed array of items in the list box. If you want to set text in the text box, set the combo boxs Text property. Heres an example; in this case, we add four items to a combo boxs list:
Private Sub Form_Load()
Combo1.AddItem ("Item 0")
Combo1.AddItem ("Item 1")
Combo1.AddItem ("Item 2")
Combo1.AddItem ("Item 3")
End Sub
You can also add items to the list with the List property. Here we create a fifth item and give it a caption this way:
Private Sub Form_Load()
Combo1.AddItem ("Item 0")
Combo1.AddItem ("Item 1")
Combo1.AddItem ("Item 2")
Combo1.AddItem ("Item 3")
Combo1.List(4) = "Item 4"
End Sub
Thats itthe result appears in Figure 8.7.
Responding To Combo Box SelectionsSo youve installed a new combo box in your program, SuperDuperTextPro, to let the user select new text font sizes, and the combo box is staring at youjust a blank box. How do you connect it to your code? Combo boxes are combinations of text boxes and list boxes, and that combination means that there are two sets of input events: Change events when the user types into the text box and Click or DblClick when the user uses the mouse. Note that, unlike standard list boxes, you cannot make multiple selections in a combo boxs list box.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |