DataGridViewColumn sortcolum = data.SortedColumn;
ListSortDirection dir;
data.DataSource = "";
/* Cargar datos */
data.DataSource = CCarsData.ConexionDB.CargarTable();
/* Set Grid */
if (sortcolum != null)
{
if (data.SortOrder == SortOrder.Ascending)
{
dir = ListSortDirection.Ascending;
}
else
{
// Sort a new column and remove the old SortGlyph.
dir = ListSortDirection.Descending;
}
data.Sort(sortcolum, dir);
sortcolum.HeaderCell.SortGlyphDirection =
dir == ListSortDirection.Ascending ?
SortOrder.Ascending : SortOrder.Descending;
}
I can already determine by which column the DataGridView is ordered
but when you refresh the object, and sort by the same field, it generates an error,
{DataGridViewTextBoxColumn { Name=campo8, Index=0 }}
all this, just after refreshing the DV.
The line that causes the error:
data.Sort(sortcolum, dir);
The error message:
The column provided does not pertain to this DataGridView control.