Eline Sami

Eline Sami

  • NA
  • 47
  • 70.2k

Sort the datagridview based on a cell value

May 4 2015 12:12 AM
Hi Vulupes and Ishan

in DatagridView (not bound to DB), would like to sort rows based on the priority of the row.

I have one method that change the fontcolor of row based on the priority

//Part of method///
if((row.cells[0].value).toString()=="High")
{
row.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
}


but I want all the rows that have red fontcolor to be displayed on the top of the list. In other words, if I set or change the importance of row to "high" then the row will be displayed automatically to the top of the list.

I have one method for sorting, but it doesn't work as I want:

private void SortRows()
{
dgv.Sort(dgv.Columns[0], ListSortDirection.Descending);
}


Answers (4)