Hi there,
I have this datagridview filled with data from a csv file. Clicking the headers of the DGV is sorting the columns. So far so good, but what I want is the DGV automatically gets sorted in column 1, when the form opens, without having to click the header.
gives the error:
'Data-bound datagridview control can only be sorted on data-bound columns'
ok..Assuming that 1st column is not bound then how to order on that column in vb-code?
Thanks !
Full code:
I have this datagridview filled with data from a csv file. Clicking the headers of the DGV is sorting the columns. So far so good, but what I want is the DGV automatically gets sorted in column 1, when the form opens, without having to click the header.
VB.NET:
Form1.DataGridView1.Sort(Form1.DataGridView1.Columns(0), ListSortDirection.Descending)
gives the error:
'Data-bound datagridview control can only be sorted on data-bound columns'
ok..Assuming that 1st column is not bound then how to order on that column in vb-code?
Thanks !
Full code:
VB.NET:
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pname & "\;Extended Properties='text;HDR=no;FMT=Delimited'"
Dim objConn As New OleDb.OleDbConnection(sConnectionString)
objConn.Open()
Dim objCmdSelect As New OleDb.OleDbCommand(stringsamen & fname, objConn)
Dim objAdapter1 As New OleDb.OleDbDataAdapter
objAdapter1.SelectCommand = objCmdSelect
Dim objDataset1 As New DataSet()
Try
objAdapter1.Fill(objDataset1, "Table1")
Form1.DataGridView1.DataSource = objDataset1.Tables(0)
Catch ex As Exception
MsgBox(ex.Message)
End Try
objConn.Close()
Form1.DataGridView1.Sort(Form1.DataGridView1.Columns(1), ListSortDirection.Descending)