Programmer 的進程 - 由 VB6 開始

Visual Basic 相關文件及程式庫 => Visual Basic.Net 範例及函式庫 => Topic started by: admin on May 29, 2012, 02:24:22 AM

Title: Datagridview 自訂排序的方式(數字或日期)
Post by: admin on May 29, 2012, 02:24:22 AM
Datagridview - Sorting Numeric Columns that are not bound to a DataSource
http://tedshelloworld.blogspot.com/2008/05/datagridview-sorting-numeric-columns.html (http://tedshelloworld.blogspot.com/2008/05/datagridview-sorting-numeric-columns.html)

Code: [Select]
    Private Sub dgvSample_SortCompare(sender As Object, e As System.Windows.Forms.DataGridViewSortCompareEventArgs) Handles dgvSample.SortCompare
        If e.Column.Index = 1 Then
            If Integer.Parse(e.CellValue1) > Integer.Parse(e.CellValue2) Then
                e.SortResult = 1
            ElseIf Integer.Parse(e.CellValue1) < Integer.Parse(e.CellValue2) Then
                e.SortResult = -1
            Else
                e.SortResult = 0
            End If
            e.Handled = True
            Exit Sub

        End If
    End Sub