Advertisement
MbahAgis

ReSorting UnBound DataGridView

Aug 6th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.89 KB | None | 0 0
  1.  
  2.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3.  
  4.         '----------UnBound----------
  5.           Dim a, b As New DataGridViewTextBoxColumn
  6.           a.HeaderText = "ID"
  7.           b.HeaderText = "Name"
  8.           DGV.Columns.Add(a)
  9.           DGV.Columns.Add(b)
  10.           For i = 0 To 9
  11.               DGV.Rows.Add("F-" & i + 1, Chr(i + 65))
  12.           Next
  13.         '------------------------------
  14.  
  15.     End Sub
  16.     Private Sub DGV_SortCompare(sender As Object, e As DataGridViewSortCompareEventArgs) Handles DGV.SortCompare
  17.           If e.Column.Index = 0 Then
  18.              Dim a As Integer = Integer.Parse(e.CellValue1.ToString().Replace("F-", Nothing))
  19.              Dim b As Integer = Integer.Parse(e.CellValue2.ToString.ToString().Replace("F-", Nothing))
  20.              e.SortResult = a.CompareTo(b)
  21.              e.Handled = True
  22.           End If
  23.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement