Home > Net >  DataGridView not sorted
DataGridView not sorted

Time:11-04

 
With DataGridView1
Sort () Columns (1), ListSortDirection. Ascending)
End With

When running this code System. ArgumentException: the type of the object must be a String, "" error. Consult everybody a great god this what is the problem

CodePudding user response:

The Columns (1) is the data type of the String?

CodePudding user response:

Write clearly wrong, the first column is zero, and the need to STRING type

CodePudding user response:

reference 1st floor moou00 response:
Columns (1) is the data type of the String?
should be sorted in two columns of data type is text xx. XxMM.

CodePudding user response:

refer to the second floor??????????? Response:
write plainly in the wrong, the first column is zero, and the need to type STRING
need sequence is the second column is not the first column

CodePudding user response:

DataGridView1. Sort (DataGridView1. Columns (1), System.Com ponentModel. ListSortDirection. Ascending)
There is no problem!

CodePudding user response:

An error when CELLs is empty, try using the following statement
Private Sub DataGridView1_SortCompare (ByVal sender As Object, ByVal e the As System. Windows, Forms the DataGridViewSortCompareEventArgs) Handles DataGridView1. SortCompare
If e.c. with our fabrication: ellValue1. ToString (). Length=0, AndAlso e.c. with our fabrication: ellValue2. The ToString (). The Length=0 Then
E.S ortResult=0
E.H andled=True
ElseIf e.c. with our fabrication: ellValue1. ToString (). Length=0 Then
E.S ortResult=1
E.H andled=True
ElseIf e.c. with our fabrication: ellValue2. ToString (). Length=0 Then
E.S ortResult=1
E.H andled=True
The Else
E.H andled=False
End the If
End Sub
  • Related