It turned out something like this:
DataTable dt = new DataTable(); dt.Columns.Add("i1", typeof(int)); dt.Columns.Add("b1", typeof(bool)); dt.Columns.Add("b2", typeof(bool)); dt.Rows.Add(1, false, false); dt.Rows.Add(2, true, false); dt.Rows.Add(3, true, true); dt.Rows.Add(4, false, true); var rows = dt.Rows.Cast<DataRow>().ToList(); rows.Sort((x,y) => { int c = 0; foreach(var f in x.ItemArray) { if(f is bool && (bool)f) c++; } foreach(var f in y.ItemArray) { if(f is bool && (bool)f) c--; } return c; }); foreach(var r in rows) { Console.WriteLine(r["i1"]); }
Sorts by the number of true values. And feed the resulting List<DataRow> to the DataGridView.DataSource . I think more you adapt to your goals if it is still relevant.