Eline Sami

Eline Sami

  • NA
  • 47
  • 68.6k

Sort the datagridview list based on the priority of the row

May 6 2015 11:53 PM
Hi Vulupes and Ishan

I asked this question before, but till now I am still looking for the right answer. I tried to search on this but no luck so far :-(
Hope you can help me on this?

In windows form application - C#. I have a 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 wish I can sort with this order: way>>High>>Medium>>Low

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 (1)