Creating a seperator in a combobox

E

Edwin Verwer

The idea is to create a combobox with multiple value's and to seperate them
with a line or some tekst that would function like a catagorie.
This line or catagorie should not be able te be selected.
Is this possible?

example:

Value1 (selectable)
Value2 (selectable)
--------- (not selectable)
Value3 (selectable)
 
G

Gordon Bentley-Mix

Edwin,

Bit clunky but it works. Somebody might have a better suggestion but here's
mine.

Assume a ComboBox called ComboBox1 on a UserForm called UserForm1. The code
in the UserForm1 module:

Option Explicit
Dim PrevLI As Integer

Private Sub UserForm_Initialize()
Dim myArray() As String
myArray = Split("Value 1|Value 2|--------|Value 3|Value 4", "|")
ComboBox1.List = myArray
PrevLI = -1
End Sub

Private Sub ComboBox1_Change()
Dim CurrentLI As Integer
Dim Direction As String
CurrentLI = ComboBox1.ListIndex
If CurrentLI > PrevLI Then Direction = "D" Else Direction = "U"
Select Case CurrentLI
Case 2
Select Case Direction
Case "D"
CurrentLI = 3
Case "U"
CurrentLI = 1
End Select
Case Else
'Do nothing
End Select
ComboBox1.ListIndex = CurrentLI
PrevLI = CurrentLI
End Sub

If you are moving "down" the list then selecting the separator changes the
selection to the next item down, and moving "up" selects the next item up.

Repeat as necessary for each separator in the list.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

Doug Robbins - Word MVP on news.microsoft.com

There is no functionality for that, but you could sort of do it by having
whatever code it is that is running on an event associated with the
combobox, check for the ListIndex attribute of the combobox to determine if
a separator line is selected.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top