I'm trying to sort a DataTable
that contains some dates and values. I pass the DataTable
information to a DataGridView
and sort the data, then try to pass it back.
The below code runs successfully, but does not produce any difference:
Form1.DataGridView1.DataSource = ChartTable
Form1.DataGridView1.Sort(Form1.DataGridView1.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
ChartTable = CType(Form1.DataGridView1.DataSource, DataTable).Copy()
ChartTable = ChartTable.DefaultView.ToTable
For i = 0 To ChartTable.Rows.Count - 1
Debug.Print("ChartTable = " & ChartTable.Rows(i)(0) & ", DataGrid = " & Form1.DataGridView1.Rows(i).Cells(0).Value)
Next
Here's the Output from the Debug.Print
ChartTable = 30/12/15, DataGrid = 27/10/15
ChartTable = 27/10/15, DataGrid = 19/11/15
ChartTable = 29/12/15, DataGrid = 22/12/15
ChartTable = 22/12/15, DataGrid = 29/12/15
ChartTable = 19/11/15, DataGrid = 30/12/15
The ChartTable
(which is the DataTable) is still in it's original un-sorted state.
Am I missing something?
DataGridView
, it's only being used to try and provide sorting - LBPLCDataGridView1.Sort(Form1.DataGridView1.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
? - nbadaudDebug.Print
shows that the datagridview has been sorted in ascending order - LBPLC