From: Andrew Clark on
Hello,

I would like to have a combo box on my form where the data in the list is
not editable. I tried this:

Private Sub cmbLibs_Change()
If 0 <= cmbLibs.ListIndex And _
cmbLibs.ListIndex <= cmbLibs.ListCount Then
LastIndex = cmbLibs.ListIndex
Else
cmbLibs.ListIndex = LastIndex
End If
End Sub

but that always brings me back to the first list item. The idea is that
when the user edits the field I want to list to reset to the last "good"
index. Any idea what's wrong?

Thanks,
Andrew
From: Rick Rothstein on
> I would like to have a combo box on my form where the data in the list
is
> not editable.

Change the Style property of the ComboBox to 2-DropdownList in the
Properties window at design time.

Rick - MVP

From: Ken Halter on
"Andrew Clark" <nospam(a)nospam.com> wrote in message
news:1108133933.d58f2c3091bb0daa5fee9bf24a1c972a(a)teranews...
> Hello,
>
> I would like to have a combo box on my form where the data in the list is
> not editable. I tried this:


If you set the Style to 2, the edit box is read-only
'===============
Private Sub Form_Load()
With Combo1
'Set .Style = 2 'Dropdown list (property read-only at runtime)
If .Style <> 2 Then
MsgBox "Set the Style to Dropdown List"
End If
.AddItem "This"
.AddItem "That"
.AddItem "The Other"
.ListIndex = 0
End With
End Sub
'===============

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..


From: Andy on

And if you want to put any code as an action when user
chooses any item from your Combo box, don't use Change
event (it does not fire in this Style) - use Click event.

I'm saying this because if you double-click on the combo
box, you go to Change event. I've done it myself and the
code in change event did not work. :(

--- Andy

>-----Original Message-----
>> I would like to have a combo box on my form where the
data in the list
>is
>> not editable.
>
>Change the Style property of the ComboBox to 2-
DropdownList in the
>Properties window at design time.
>
>Rick - MVP
>
>.
>
From: Andrew Clark on
"Andy" <Andrzej7(a)hotmail.com> wrote in news:208901c5104f$abe96e30
$a601280a(a)phx.gbl:

>
> And if you want to put any code as an action when user
> chooses any item from your Combo box, don't use Change
> event (it does not fire in this Style) - use Click event.
>
> I'm saying this because if you double-click on the combo
> box, you go to Change event. I've done it myself and the
> code in change event did not work. :(
>
> --- Andy
>

I would also like to have some startup text in the box before the user
picks from the list, but I can't set the text in properties and if I try
this:

Form_Load()
[...]
cmbLibs.Text = "blah blah"
End Sub

I get a run time error that says field is read-only. Any suggestions?

Andrew


 |  Next  |  Last
Pages: 1 2 3
Prev: Can't edit module.
Next: Converting Strings to Formulas