Public Declare Unicode Function StrCmpLogicalW Lib "shlwapi" (x As String, y As String) As Integer Private bFlag As Boolean '昇順、降順フラグ Private Sub DataGridView1_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick Dim dt As DataTable = CType(DataGridView1.DataSource, DataTable) Dim dv As DataView = dt.DefaultView bFlag = Not bFlag For Each SelectedColumn As DataGridViewColumn In DataGridView1.SelectedColumns If SelectedColumn.Index = 0 Then 'dv.Sort = StrCmpLogicalW(dv.CellValue1?.ToString(), dv.CellValue2?.ToString()) '1列目のソートAPI呼び出し(エラー) If bFlag Then DataGridView1.Columns(0).HeaderCell.SortGlyphDirection = SortOrder.Ascending Else DataGridView1.Columns(0).HeaderCell.SortGlyphDirection = SortOrder.Descending End If ElseIf SelectedColumn.Index = 1 Then 'dv.Sort = StrCmpLogicalW(dv.CellValue1?.ToString(), dv.CellValue2?.ToString()) '2列目のソートAPI呼び出し(エラー) If bFlag Then DataGridView1.Columns(1).HeaderCell.SortGlyphDirection = SortOrder.Ascending Else DataGridView1.Columns(1).HeaderCell.SortGlyphDirection = SortOrder.Descending End If End If Next DataGridView1.DataSource = dv End Sub