Value list for a combo box

I want to make a simple value list hard-coded as the selection for a combo box in VB.NET 2.0. Where do I enter the values



Answer this question

Value list for a combo box

  • Rognprisy

    I really doubt its because its an integer.

    Perhaps I'm not understanding your question correctly as you are now talking about an underlying set.

    The items property defines what items are in the combo box. If you have only 4 items in the combobox then you should only see 4 items in here. You now talk about an underlying set

    You need to describe what this is an actually what your trying to achieve in a bit more detail so we can figure out what your trying to do. It sounds at the moment as though the underlying set is populating the combobox at run-time and this is why you are seeing all these items. If this is so then you'll need to find this code and modify it.


  • JMattias

    Im not sure what 2.0 is but the same is true for .net and the combo box.

    Select ComboControl in designer, Press F4 to display properties windows, locate the Items property which will display as Collection ... click this and then you can just type the values in.

    In 2005/Express this can be reached even quicker by selecting the control, you'll notice a little sort of arrow character which can be clicked and a menu appears - select edit items and your at the same point where you can add hard coded items into the items collection property of the control.


  • JimBarry

    I think your problem was probably that you were binding to the access database.

    Without the databindings in place its as simple as setting the items property for the control at design time.

    You had the databindings set which means that at runtime this will overwrite the items collection with data from your access database.


  • Valeh

    OK, here is what I need:

    The underlying table has a smallint column whose value is limited to 0, 1, 2 or 3.\

    In the Data properties for the combobox, I entered the column name as DataPropertyName, the table name as DataSource, the column name as DisplayMember and (none) as the ValueMember. I've tried entering the values into the Items (Collection) box as values and as strings. But when the form runs, the combo box displays all of the underlying records (multiple 0s, 1s, 2s, and 3s) as selections.

    When I return to the design, there is nothing in the Items collection.

    I need the combo box to offer 0, 1, 2 or 3 as a valid selection for the column.

    Thanks for your continuing help.


  • Don Juan

    Whats happening is that you are binding to a data source - this is where it is getting the data to populate the combobox - hence its showing all the values from the table.

    This occurs at run time when it will do the data binding.

    You have a few options here - one would be to not use data binding and simply populate the combobox items manually (either at design time or at run-time) In which case get rid of the datasource, datapropertyname and Display member and populate the items collection with the items 0,1,2,3 on separate lines. This will mean these will be the only values show in the combo box.

    The other is to use either use a different table that contains only the records you want to populate in and use this as the datasource, so there would only be 4 records in this table used for the databinding.

    Another would be to create a datasource which is used for the binding that uses a SQLstatement to populate the datasource. An example may be creating a dataset which does something like SELECT Distinct <field> FROM <Table> Group By <Field>this can be used to populate a dataset which would become you data source.

    My preference for simplicity and if you only want 3 valid selections is the first - its simple and should give you a hardcoded value list.


  • Patrick Baker - MSFT

    Thanks for your help. I knew it would be complicated. I'm accustomed to the luxury of Access where you only have to type in the list separated by semi-colons. Why this approach couldn't be used with VB.NET is beyond me.


  • jmst

    I tried this, but it didn't work the way I wanted. I typed in "0 1 2 3" on separate lines, but the result is that the selection list includes every record from the underlying set (800 variations in all). I'm wondering if this is because the field has integers rather than strings.

    Thanks for replying.


  • Value list for a combo box