Jan 7th, 2006, 10:31 PM
#1
Thread Starter
Junior Member
ComboBox, Turn off Highlighting
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
Jan 7th, 2006, 10:33 PM
#2
PowerPoster
Re: ComboBox, Turn off Highlighting
i dont believe it can be done
Jan 7th, 2006, 10:35 PM
#3
Re: ComboBox, Turn off Highlighting
Welcome to the forums!
Try:
when you want it unselected.
Jan 8th, 2006, 12:45 AM
#4
Re: ComboBox, Turn off Highlighting
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
Jan 8th, 2006, 01:15 AM
#5
Re: ComboBox, Turn off Highlighting
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.
Jan 8th, 2006, 01:31 AM
#6
Re: ComboBox, Turn off Highlighting
Other then getting real complicated, you can do like posted to set the focus somewhere else or set the .SelLength = 0 and the .SelText = ""
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
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/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 8th, 2006, 01:37 AM
#7
Re: ComboBox, Turn off Highlighting
Can you actually set those properties?
Jan 8th, 2006, 01:47 AM
#8
Re: ComboBox, Turn off Highlighting
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?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 8th, 2006, 04:15 AM
#9
Re: ComboBox, Turn off Highlighting
not working Rob. error is "Out of Stack" and highlights the "Combo1.SelText = """ under Change event.
or am i doing something wrong?
Jan 8th, 2006, 08:13 AM
#10
Re: ComboBox, Turn off Highlighting
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
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 8th, 2006, 12:33 PM
#11
Re: ComboBox, Turn off 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
Private Sub Form_Load()
Combo1.AddItem "item1"
Combo1.AddItem "item2"
Combo1.AddItem "item3"
End Sub
i tried this code and it gives me this error on clicking the combo box for dropping it:
"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.
Jan 8th, 2006, 12:35 PM
#12
Re: ComboBox, Turn off Highlighting
Its the same as you have. Only thing I can think of is that my cbo is Style - 0.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 8th, 2006, 12:42 PM
#13
Re: ComboBox, Turn off Highlighting
Originally Posted by
RobDog888
Its the same as you have. Only thing I can think of is that my cbo is Style - 0.
same here
Jan 8th, 2006, 12:48 PM
#14
Re: ComboBox, Turn off Highlighting
Using your exact code it still works for me. Selecting an item or clicking or ?? No errors.
Attached Files
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 8th, 2006, 01:43 PM
#15
Re: ComboBox, Turn off Highlighting
ahh, i give up. dont understand what's wrong.
searched MSDN, but no help
thnak you Rob.
Jan 8th, 2006, 02:07 PM
#16
Re: ComboBox, Turn off Highlighting
Robert, I've tried the zipped code. It isn't doing *anything*. The text is still highlighted.
Jan 8th, 2006, 02:08 PM
#17
Re: ComboBox, Turn off Highlighting
I know that it doesnt work when you click on an item but it works for keypresses. as I posted in #6.
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Jan 8th, 2006, 02:25 PM
#18
Re: ComboBox, Turn off Highlighting
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
Jan 25th, 2006, 09:58 AM
#19
New Member
Re: ComboBox, Turn off Highlighting
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
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width