With DataGridView1
.Sort(.Columns(1), ListSortDirection.Ascending)
End With
運行這段代碼時出現 System.ArgumentException:“物件的型別必須是 String。” 錯誤 .請教各位大神這有何問題
uj5u.com熱心網友回復:
Columns(1) 的資料型別是 String嗎?uj5u.com熱心網友回復:
顯然寫錯了。第一列是0。并且需要STRING型別uj5u.com熱心網友回復:
需排序列是二列 里面的資料 是文本型 xx.xxMM.uj5u.com熱心網友回復:
需要排序列是第二列不是第一列uj5u.com熱心網友回復:
DataGridView1.Sort(DataGridView1.Columns(1), System.ComponentModel.ListSortDirection.Ascending)沒有問題吧
uj5u.com熱心網友回復:
當CELLs為空時會報錯,使用如下陳述句試試Private Sub DataGridView1_SortCompare(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewSortCompareEventArgs) Handles DataGridView1.SortCompare
If e.CellValue1.ToString().Length = 0 AndAlso e.CellValue2.ToString().Length = 0 Then
e.SortResult = 0
e.Handled = True
ElseIf e.CellValue1.ToString().Length = 0 Then
e.SortResult = -1
e.Handled = True
ElseIf e.CellValue2.ToString().Length = 0 Then
e.SortResult = 1
e.Handled = True
Else
e.Handled = False
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/3686.html
標籤:VB.NET
上一篇:Windows換圖
