Newsgroup: it.comp.lang.visual-basic
Titolo: ComboBox Questions

I am working with several ComboBox controls in a VB 6.0 project I'm
working on and I have several questions regarding the population and
control of these various ComboBoxes...
First of all, for example, I have one combobox control named
"cboState" that contains the abbreviations for all 50 states in the
United States.  There is an mxFlexGrid control located on the form
above the "ComboBox" control that contains several columns/rows of
information.  If a user clicks on a row of information in the
msFlexGrid, code runs that picks each item out of each column in the
row and populates corresponding fields for each column... one of those
fields being the "cboState" combobox.  This functionality is setup
this way as to allow an individual to select a record present in the
msFlexGrid control, and have all of the information present in the
selected row in the msFlexGrid carried down to individual fields so
that each field of information may be edited.
When I attempt to populate the "cboState" combobox field, VB informs
me that the "cboState" field's "Text" property is read-only.
The "cboState" field's Style property is currently set to "2 -
Dropdown List" due to me wanting to prohibit the user from entering
anything in this field other than the accepted 2-character
abbreviations for the 50 U.S. states.  I've noticed that if I adjust
the Style property of the "cboState" field to "0 - Dropdown Combo",
the "cboState" field is allowed to be populated with the 2-character
state abbreviation selected in the msFlexGrid control on the form. 
This is fine, except that a Style setting of "0 - Dropdown Combo"
allows the user to enter anything they want into this field, and the
entire purpose of the field is to restrict the user from entering
anything that isn't a valid selection item from the combobox control.
I'm beginning to think that the best option for how I'm wanting the
majority of the various ComboBox controls to operate is to change the
Style property of the controls from "2 - Dropdown List" to "0 -
Dropdown Combo" and implement some type of error control or data
validation to verify that whatever the user enters into the ComboBox
control is indeed a valid selection item for the control.  If this is
the case, does anyone have some code that they routinely use for data
validation purposes of this nature with ComboBoxes?
Many thanks in advance for any assistance anyone can provide w/respect
to these issues.
Sincerely,
Brad H. McCollum
bmcc...@yahoo.com

 abbreviations for the 50 U.S. states.
It seem to me that your problem is not to populate the combo box, but to
find the right item in the list.
If you want to populate the combo-box, you have to use the AddItem method,
that works either with Dropdown List and Dropdown Combo.
Using Text property, you only change the value displayed in the control's
text part. When you try to do this in DropDown List mode, if you insert a
text not included in the item list, the control refuse the command and raise
the "read only" error.
On the other hand, if  you try to change the text property to a value
included in the item list, all works perfectly, and your list will now point
to the correct item.
May be you enter a default null text value, that works with a Dropdown
Combo, and doesn't with a Dropdown List.
Solution? Just trap the error and ignore it.
Bye
*Bob*
P.S.
This is an italian newsgroup. Foreigners visitors are welcome, but only if
they speak italian. ;-)