Jump to content

Recommended Posts

Posted

I have a combobox that I've populated with the names of all the layers in the drawing. In the dropdown list the layers are not ordered.

 

Is there a way to order the layer names alphabetically?

 

Thanks

Posted

Presume that you are talking about DCL combo box - in this case ACAD_STRLSORT statement is the answer. If is about VBA, there is an option at design time for sorted combo box (in Properties).

 

Regards,

Posted

I'm using Standard VBA with no additional references, but I can see no option in the ComboBox Properties that relates to sorting the entries.

Posted

You are right – I confused with VB where this option is available. Sorry for inconvenience.

For VBA will require to use a sort routine:

Private Sub SortComboBoxEntries(ByVal theComboBox As ComboBox)
On Error Resume Next
   Dim EntryOld, EntryNew As String
   Dim CrIndex As Integer

   For CrIndex = 0 To (theComboBox.ListCount - 1)   'parse combo box entries
       EntryOld = theComboBox.List(CrIndex)
       EntryNew = theComboBox.List(CrIndex + 1)

       If EntryOld > EntryNew Then                  'compare with below entry
           theComboBox.List(CrIndex) = EntryNew     'and switch location if bigger
           theComboBox.List(CrIndex + 1) = EntryOld

           CrIndex = 0                              'reset to first index
       End If
   Next CrIndex
End Sub

 

Regards,

Posted

The comboBox has a sort list property in VB.NET, but not in VBA.

 

With the help from MATT W from TheSwamp I now have the Layer list in the ComboBox sorted.

 

@ msasu,

I had already worked out the code before I got your reply, but yours looks a lot neater. I shall try it out and let you know.

Posted

msasu your code works a treat.

 

Many thanks.

Posted

You’re welcomed!

Not sure about the other solution that you have – but may be faster that mine, since it have to re-wind the counter many time for a long, scrambled list and therefore can led to a time issue.

 

Regards,

Posted

The length of the list of layers is short and takes no time at all to sort, at most 40 layers.

your code is very compact and can easily be fitted in to any module.

 

Point taken about how it works and perhaps with very long lists performance would be an issue.

 

Thanks again.

  • 5 years later...
Posted
You are right – I confused with VB where this option is available. Sorry for inconvenience.

For VBA will require to use a sort routine:

Private Sub SortComboBoxEntries(ByVal theComboBox As ComboBox)
On Error Resume Next
   Dim EntryOld, EntryNew As String
   Dim CrIndex As Integer

   For CrIndex = 0 To (theComboBox.ListCount - 1)   'parse combo box entries
       EntryOld = theComboBox.List(CrIndex)
       EntryNew = theComboBox.List(CrIndex + 1)

       If EntryOld > EntryNew Then                  'compare with below entry
           theComboBox.List(CrIndex) = EntryNew     'and switch location if bigger
           theComboBox.List(CrIndex + 1) = EntryOld

           CrIndex = 0                              'reset to first index
       End If
   Next CrIndex
End Sub

 

Regards,

 

It's very usefull to me. My small work have done.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...