I have a DataGridView that holds data returned from a stored procedure on a database. The columns are different for each return value, so do not have strongly-typed names. I'm currently struggling to order these, as the numeric columns are being ordered as strings, eg. 1 -> 10 -> 11 -> 15 -> 2 -> 25 -> 3, and not by value. I've confirmed that the ValueType of the column is being set correctly. I have tried this:
var sortedRows = from row in _rowArray
orderby columnIndex
select row;
_rowArray = sortedRows.ToArray();
where _rowArray is an array of DataRows, and is the DataSource of the DataGridView, and columnIndex is an integer variable specifying which column in _rowArray the user wants to order by. While debugging, I can see that the sortedRows holds the same sequence as _rowArray in the same order, immediately following the LINQ statement. I have also tried:
_rowArray = _rowArray.OrderBy(r => r[columnIndex]).ToArray();
and have tried creating a DataView (view) and done this:
view.Sort = m_data.Tables[0].Columns[columnIndex].ColumnName + " ASC";
...but that hasn't worked. Anyone offer any insight?