title: OrderBy named index
body: <p>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:</p>
  
  <pre><code>var sortedRows = from row in _rowArray
                               orderby columnIndex
                               select row;
                  _rowArray = sortedRows.ToArray();
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>_rowArray = _rowArray.OrderBy(r =&gt; r[columnIndex]).ToArray();
  </code></pre>
  
  <p>and have tried creating a DataView (view) and done this:</p>
  
  <pre><code>view.Sort = m_data.Tables[0].Columns[columnIndex].ColumnName + " ASC";        
  </code></pre>
  
  <p>...but that hasn't worked. Anyone offer any insight?</p>