Results 1 to 3 of 3

Thread: ListBox & ComboControl Tips

  1. #1
    Join Date
    Jun 2009
    Posts
    230

    ListBox & ComboControl Tips

    These controls are used to display a list of values in which the user can choose one or more values. The list box remains fixed and deployed while the combo box appears as a text box with a triangle on the right that allows you to display all the values in the list. One of the easiest ways to create a control like this is using the Control Wizard. Usage is very simple, you only need to activate the wizard before creating the control on the form or report by clicking on its icon in the Toolbox. Once activated, the wizard, when trying to create a list box control or combo box will launch an automatic generator control, following a few simple steps, complete control properties to display the data you want.

    ListBox Control

    ListBox Control (List) allows the user to select from a list of data (One or several at once). In Visual Basic 6, it was common as well as adding a string to the ListBox also like to add or link a numeric value with the string in the VB version of the method we used to associate ItemData this numerical value, so that each string contained in the ListBox could have an associated numerical value. But. NET ListBox control ItemData not have a method (or a property indicating NewIndex the last index which was added to the ListBox), not only strings are added, as the Items collection that can take are elements of type Object, So we can add any type of data in that collection, not just strings, as in the VB6 ListBox.

    In VB6, the elements were of type String, no problems with what was shown in control, because what was shown was precisely the content of the chains that had been added, but because the type of data is added to the Items collection of a ListBox. NET is of type Object. NET Framework does is show how to return the ToString method of each object, we add a string, it displays the contents of the string, add numeric values, shows the contents of those numbers.

    Sample Code :
    • Class LBItem
    • As String Public Content
    • Public Value As Integer
    • End Class

    • Public Sub New (c As String, v As Integer)
    • Content = c
    • Value = v
    • End Sub

    The entries in a ListBox can be sorted easily by setting the Sorted property to the development time is set to True.

    ComboControl

    This control is widely used in programs allows us through a drop-down list to select items, as it is also possible to introduce the same. Another type of views are as follows ComboBox control, you change from the control's Style property.
    • Single Column DropDown : The single DropDown column is an kind of the default style and displays the list when you click the arrow.
    • Multiple Column DropDown : There is another type where you get multiple columns in the singel box which displayed the list and has a button to display the items.
    • Search DropDown: The third type is is like the DropDown, but with the difference that you can enter text, you can only select items.his control is very similar to the List control in regard to the properties and methods for managing data, to add items using the AddItem method.


    Code for adding 50 item in Next Loop

    Code:
    Dim element As Integer 
     For Item = 0 To 50 
    'Add the value of the variable element to Combo 
     Combo1.AddItem i 
     Next
    
    Like the ListBox control to delete the contents using the Clear method
    
    'Delete all the contents 
     Combo1.Clear
    Like the List control to ascertain the value of a particular item using the List property specifying the item number, ListCount (for the number of elements), ListIndex (know the selected item) RemoveItem Method (Eliminates specified item) etc.

    DataField and DataSource Property are two properties present in the ListBox and ComboBox control, as well as several other Visual Basic controls such as Label, TextBox, etc ..., enables setting bind the controls to a database. The first one DataField returns or sets a value that binds a control with a field of current record. And the second one DataSource, sets a value that specifies the data control through which the current control is linked to a database

  2. #2
    Join Date
    Apr 2009
    Posts
    569

    Re: ListBox & ComboControl Tips

    I think that it might have been easier to integrate into the command button procedure. But while you learn the same, as you pass objects to a procedure. You can use the procedure for ListBoxFüllen multiple listboxes,
    We handed over our control of the procedure - ListBox1 and the area in such a way that it does not matter sheet on which the user is currently located and in what workbook. Now comes the really exciting. A list box has the property list. This is nothing more than a two dimensional list with rows and columns. Excel VBA provides us the opportunity available to the list directly to fill out a Range. But we still need to tell her how much she has column - and we read out the number of columns of the Range.

  3. #3
    jeniferjohn Guest

    Re: ListBox & ComboControl Tips

    Method 1: How to Link a Combo Box or List Box to Cells on an Excel Worksheet

    1. Create a new workbook in Microsoft Excel. On Sheet1, type the
    following:

    A1: One B1: Red
    A2: Two B2: Green
    A3: Three B3: Yellow
    A4: Four B4: Blue

    2. Press ALT+F11 to start the Microsoft Excel Visual Basic Editor.
    3. On the *Insert* menu, click *UserForm*.
    4. Create a ComboBox control and a ListBox control on the user form.
    5. If the Properties window is not visible, click *Properties Window* on the *View* menu.
    6. Click the *ComboBox* and scroll to *RowSource* in the *Properties window*.

    The window is divided into two sections. The left section contains the name of the property for the control. The right section contains the value of the property. Click in the right section of RowSource and type "*sheet1!a1:a4*" (without the quotation marks).
    7. Click the *ListBox* and scroll to *RowSource* in the Properties window. Click in the right section of RowSource and type "*sheet1!b1:b4*" (without the quotation marks).
    8. Run the user form by clicking *Run* and then clicking *Run
    Sub/UserForm*.One, Two, Three, and Four appear in the ComboBox control; and Red, Green,Yellow, and Blue appear in the ListBox control.

    Methdod 2: How to Use a Visual Basic Macro to Populate a Combo Box or List
    Box

    1. Open a Microsoft Office Application such as Microsoft Excel or Word.
    2. Press ALT+F11 to start the Visual Basic Editor.
    3. On the *Insert* menu, click *UserForm*.
    4. Create a ComboBox and a ListBox control on the user form.
    5. Right-click the user form and click *View Code*. The Code window for
    the user form appears. Click *Initialize* in the *Procedure* list (on the
    right side).

    The first and last lines of the subroutine are automatically entered, and the insertion point is automatically placed between these two lines.
    6. Type the following code:

    ListBox1.List = Array("One", "Two", "Three", "Four")

    ComboBox1.List = Array("Red", "Green", "Yellow", "Blue")

    This code should appear between the lines "Sub UserForm_Initialize()" and
    "End Sub".
    7. On the *Run* menu, click *Run Sub/UserForm* to run the user form.

    One, Two, Three, and Four appear in the ListBox control; and Red, Green,yellow, and Blue appear in the ComboBox control.
    Last edited by jeniferjohn; 27-07-2011 at 04:56 PM.

Similar Threads

  1. Problem in getting an object from a listbox.
    By MABON in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 05:21 PM
  2. How to create ListBox in VB.net?
    By MarceloQuad in forum Software Development
    Replies: 4
    Last Post: 22-01-2010, 08:44 PM
  3. ListView or ListBox
    By Heather5 in forum Software Development
    Replies: 3
    Last Post: 29-08-2009, 12:10 AM
  4. C# Listbox control
    By abhinavm in forum Software Development
    Replies: 2
    Last Post: 07-08-2009, 11:01 PM
  5. I have a problem with listbox
    By StoaVio in forum Software Development
    Replies: 2
    Last Post: 25-10-2008, 03:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,005,774.32703 seconds with 17 queries