Results 1 to 19 of 19

Thread: ComboBox, Turn off Highlighting

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    29

    Talking 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

  2. #2

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: ComboBox, Turn off Highlighting

    Welcome to the forums!

    Try:
    VB Code:
    1. cmbo.SelectedIndex = -1

    when you want it unselected.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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:
    1. Private Sub Combo1_Click()
    2.  
    3.     Command1.SetFocus
    4.    
    5. End Sub

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: ComboBox, Turn off Highlighting

    Oops. I typed freehand, and was slightly wrong.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Combo1_Click()
    4.   MsgBox Combo1.List(Combo1.ListIndex) & " is ListIndex # " & Combo1.ListIndex
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8.   Dim x As Integer
    9.   For x = 100 To 1 Step -1
    10.     Combo1.AddItem x
    11.   Next x
    12.   Combo1.List(1) = "test"
    13. End Sub

    The item is highlighted after clicking on it, but after grabbing the info, you can unselect it, as I meant.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Option Explicit
    2.  
    3. Private Sub Combo1_Change()
    4.     Combo1.SelLength = 0
    5.     Combo1.SelText = ""
    6. End Sub
    7.  
    8. Private Sub Combo1_Click()
    9.     'Doesnt really work but...
    10.     Combo1.SelLength = 0
    11.     Combo1.SelText = ""
    12. End Sub
    13.  
    14. Private Sub Combo1_DropDown()
    15.     Combo1.SelLength = 0
    16.     Combo1.SelText = ""
    17. End Sub
    18.  
    19. Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
    20.     Combo1.SelLength = 0
    21.     Combo1.SelText = ""
    22. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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?
    Show Appreciation. Rate Posts.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Private Sub Form_Load()
    2.     Combo1.AddItem "Test"
    3. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  11. #11
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: ComboBox, Turn off Highlighting

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Combo1_Change()
    4.     Combo1.SelLength = 0
    5.     Combo1.SelText = ""
    6. End Sub
    7.  
    8. Private Sub Combo1_Click()
    9.     'Doesnt really work but...
    10.     Combo1.SelLength = 0
    11.     Combo1.SelText = ""
    12. End Sub
    13.  
    14. Private Sub Combo1_DropDown()
    15.     Combo1.SelLength = 0
    16.     Combo1.SelText = ""
    17. End Sub
    18.  
    19. Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
    20.     Combo1.SelLength = 0
    21.     Combo1.SelText = ""
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25. Combo1.AddItem "item1"
    26. Combo1.AddItem "item2"
    27. Combo1.AddItem "item3"
    28. 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.
    Show Appreciation. Rate Posts.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  13. #13
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: ComboBox, Turn off Highlighting

    Quote 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
    Show Appreciation. Rate Posts.

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ComboBox, Turn off Highlighting

    Using your exact code it still works for me. Selecting an item or clicking or ?? No errors.
    Attached Files 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  15. #15
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: ComboBox, Turn off Highlighting

    ahh, i give up. dont understand what's wrong.

    searched MSDN, but no help

    thnak you Rob.
    Show Appreciation. Rate Posts.

  16. #16
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: ComboBox, Turn off Highlighting

    Robert, I've tried the zipped code. It isn't doing *anything*. The text is still highlighted.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  18. #18
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. Option Explicit
    2.  
    3. Private Sub Combo1_Change()
    4.     Combo1.SelStart = 0
    5. End Sub
    6.  
    7. Private Sub Combo1_Click()
    8.     Timer1.Enabled = True
    9.     Combo1.SelStart = 0
    10. End Sub
    11.  
    12. Private Sub Combo1_DropDown()
    13.     Combo1.SelStart = 0
    14. End Sub
    15.  
    16. Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
    17.     Combo1.SelStart = 0
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21.     Timer1.Enabled = False
    22.     Timer1.Interval = 5
    23.    
    24.     Combo1.AddItem "item1"
    25.     Combo1.AddItem "item2"
    26.     Combo1.AddItem "item3"
    27. End Sub
    28.  
    29. Private Sub Timer1_Timer()
    30.     Timer1.Enabled = False
    31.     Combo1.SelStart = 0
    32. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  19. #19
    New Member Marvels's Avatar
    Join Date
    Jan 2006
    Location
    Amsterdam
    Posts
    8

    Wink 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
  •  



Click Here to Expand Forum to Full Width