Tyke Posted March 2, 2010 Posted March 2, 2010 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 Quote
MSasu Posted March 2, 2010 Posted March 2, 2010 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, Quote
Tyke Posted March 2, 2010 Author Posted March 2, 2010 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. Quote
MSasu Posted March 3, 2010 Posted March 3, 2010 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, Quote
Tyke Posted March 3, 2010 Author Posted March 3, 2010 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. Quote
Tyke Posted March 3, 2010 Author Posted March 3, 2010 msasu your code works a treat. Many thanks. Quote
MSasu Posted March 3, 2010 Posted March 3, 2010 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, Quote
Tyke Posted March 4, 2010 Author Posted March 4, 2010 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. Quote
hagialai1982 Posted January 6, 2016 Posted January 6, 2016 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. Quote
Lee Mac Posted January 6, 2016 Posted January 6, 2016 @Moderator: suggest moving this thread to the .NET, ObjectARX & VBA board. Quote
Recommended Posts
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.