I am transitioning VBA code to VB.net. I ran into an issue where I needed to create a custom sort based on three text values: Employee, Spouse, Child.
There are a few articles on custom sorts but they all revolve around either numerical values or dates. '
Here is what I have so far:
Sub Sort_information()
Dim sort_str As String
Dim dv As DataView
Dim col = 2
dv = individual.dt.DefaultView
Dim anyHasValue = Demographic_data_view.Rows.
OfType(Of DataGridViewRow).
Where(Function(r) Not r.IsNewRow AndAlso r.Cells.
OfType(Of DataGridViewTextBoxCell).
Any(Function(c) c.OwningColumn.Index = col AndAlso
If(c.Value, String.Empty).ToString().Trim().Length > 0)).
Any()
If anyHasValue = True Then
sort_str = "Employee_SSN ASC, "
Else
sort_str = "Individual_ID ASC, "
End If
dv.Sort = sort_str
Demographic_data_view.DataSource = dv
End Sub
The goal will be to sort the information based on SSN or ID (depends if SSN is provided), "Employee,Spouse,Child,", first_name, Last_name, and Plan_name
If I exclude the custom sort I can easily create a string variable to make a sort for the other columns. However, the order of employee, spouse, and child is absolutely necessary.
I really appreciate any help on this matter.
What I have tried:
I tried to find articles that were specific to custom sorting on 3 text values. but I could not come up with anything.