Нужно отсортировать строковые IP в DataGridView привязанный к DataTable.
Нашел пример который работает, если Gridview не привязан к DataTable
Public Class IPRowComparer
Implements System.Collections.IComparer
Private sortOrderModifier As Integer = 1
Public Sub New(ByVal sortOrder As SortOrder)
If sortOrder = sortOrder.Descending Then
sortOrderModifier = -1
ElseIf sortOrder = sortOrder.Ascending Then
sortOrderModifier = 1
End If
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
Implements System.Collections.IComparer.Compare
Dim DataGridViewRow1 As DataGridViewRow = CType(x, DataGridViewRow)
Dim DataGridViewRow2 As DataGridViewRow = CType(y, DataGridViewRow)
Dim IP1 As System.Net.IPAddress = System.Net.IPAddress.Parse(DataGridViewRow1.Cells("IP").Value)
Dim IP2 As System.Net.IPAddress = System.Net.IPAddress.Parse(DataGridViewRow2.Cells("IP").Value)
Return IP1.GetHashCode - IP2.GetHashCode
End Function
End Class
grdScan.Sort(New IPRowComparer(SortOrder.Ascending))
Но с привязанным DT не дает сортировать, помогите пожалуйста.
Ответить
|