Sorting of Array of a Containers

I would like to sort an array of a Containers (ccUser in this case). I have not been able to get the examples I have found to work.

Class cUser Property controlIndex As Integer Property id As Text Property firstName As Text Property lastName As Text Property employeeNumber As Integer Property Tag As Variant End Class

Private mUsers() As ccUser

[code]Public AddItem(u As cUser) As Integer
Dim c As new ccUser
Dim cTop, cWidth As Integer

c.id = u.id
c.firstName = u.firstName
c.lastName = u.lastName
c.Tag = h.Tag
c.employeeNumber = h.employeeNumber

mUsers.Append c

c.controlIndex = mUsers.Ubound
End Function[/code]

Now, what I would like to do is be able to sort mUsers() by say the lastName property or employeeNuber.

Any ideas?

You SAID “CONTAINER”… did you mean class instead?

Show us what you have attempted…

ccUser is a ContainerControl which I am embedding within a another ContainerControl. mUsers() is the array of ccUser ContainerControls that are embedded within the ccUserList Container. I use the class cUser to populate the ccUser Container.

Here are a couple of the things I have tried.

sortwith array for containercontrol array? looks like what I need but I’m not sure how to modify/implement the answer in my scenario.

Class Array Sort Question

I have also looked at Tip: Smart Sort function for arrays of objects

Use SortWith and then rearrange the containers:

Dim lastNames() As Text For i As Integer = 0 To mUsers.Ubound lastNames.Append(lastName) Next lastNames.SortWith(mUsers) For i As Integer = 0 To mUsers.Ubound mUsers(i).Top = 20 + i * 30 // or whatever the gap is between the containers Next

Note that you are duplicating data: the properties you describe above in ccUser are not necessary:

[code]Public AddItem(u As cUser) As Integer
Dim c As new ccUser
Dim cTop, cWidth As Integer

c.id = u.id
c.firstName = u.firstName // why not assign c.FirstNameTextField.Text ???

[/code]