I'm using several comboxes for selections in an application, does anyone know how to turn off or remove text highlighting after user makes a selection from combobox? Thanks
Printable View
I'm using several comboxes for selections in an application, does anyone know how to turn off or remove text highlighting after user makes a selection from combobox? Thanks
i dont believe it can be done
Welcome to the forums!
Try:
VB Code:
cmbo.SelectedIndex = -1
when you want it unselected.
Rather than making the selection disappear (which is I think what dglienna would have you do - if there were a SelectedIndex property) just set the focus someplace else like this for example.
VB Code:
Private Sub Combo1_Click() Command1.SetFocus End Sub
Oops. I typed freehand, and was slightly wrong.
VB Code:
Option Explicit Private Sub Combo1_Click() MsgBox Combo1.List(Combo1.ListIndex) & " is ListIndex # " & Combo1.ListIndex End Sub Private Sub Form_Load() Dim x As Integer For x = 100 To 1 Step -1 Combo1.AddItem x Next x Combo1.List(1) = "test" End Sub
The item is highlighted after clicking on it, but after grabbing the info, you can unselect it, as I meant.
Other then getting real complicated, you can do like posted to set the focus somewhere else or set the .SelLength = 0 and the .SelText = ""
The combo box control is lacking a mouseup event which would really help out too. Its not a complete solution but at least it retains your selection just without the highlighting.VB Code:
Option Explicit Private Sub Combo1_Change() Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Combo1_Click() 'Doesnt really work but... Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Combo1_DropDown() Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer) Combo1.SelLength = 0 Combo1.SelText = "" End Sub
Can you actually set those properties?
Test it. Add a combobox to a form and paste in the code. Combo style = 0
Edit: the poster never stated what the style was?
not working Rob. error is "Out of Stack" and highlights the "Combo1.SelText = """ under Change event.
or am i doing something wrong?
It works fine for me with the exception that I have this additional procedure to load an item.
VB Code:
Private Sub Form_Load() Combo1.AddItem "Test" End Sub
i tried this code and it gives me this error on clicking the combo box for dropping it:VB Code:
Option Explicit Private Sub Combo1_Change() Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Combo1_Click() 'Doesnt really work but... Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Combo1_DropDown() Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer) Combo1.SelLength = 0 Combo1.SelText = "" End Sub Private Sub Form_Load() Combo1.AddItem "item1" Combo1.AddItem "item2" Combo1.AddItem "item3" End Sub
"Run-time error: 28
Out of Stack space"
and highlightes Combo1.SelText = "" under Change event. if i comment out that line, then nothing happens. it still remains highlighted.
could you please post the whole code you used?
thank you.
Its the same as you have. Only thing I can think of is that my cbo is Style - 0.
same here :confused:Quote:
Originally Posted by RobDog888
Using your exact code it still works for me. Selecting an item or clicking or ?? No errors.
ahh, i give up. dont understand what's wrong.
searched MSDN, but no help :(
thnak you Rob.
Robert, I've tried the zipped code. It isn't doing *anything*. The text is still highlighted. :confused:
I know that it doesnt work when you click on an item but it works for keypresses. as I posted in #6. :(
I guess the Click event fires before the text gets updated. Adding a timer seems solve the problem.
VB Code:
Option Explicit Private Sub Combo1_Change() Combo1.SelStart = 0 End Sub Private Sub Combo1_Click() Timer1.Enabled = True Combo1.SelStart = 0 End Sub Private Sub Combo1_DropDown() Combo1.SelStart = 0 End Sub Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer) Combo1.SelStart = 0 End Sub Private Sub Form_Load() Timer1.Enabled = False Timer1.Interval = 5 Combo1.AddItem "item1" Combo1.AddItem "item2" Combo1.AddItem "item3" End Sub Private Sub Timer1_Timer() Timer1.Enabled = False Combo1.SelStart = 0 End Sub
For llIndex = 0 To ocboQueryCode.ListCount - 1
If LCase(ocboQueryCode.List(llIndex)) = LCase(ocboQueryCode.Text) Then
ocboQueryCode.ListIndex = llIndex
ocboQueryCode.SelLength = 0
ocboQueryCode.SelStart = Len(ocboQueryCode.Text)
Exit For
End If
Next