简体   繁体   English

如何按单元格颜色对datagridview进行排序?

[英]how do i sort datagridview by cell color?

i want to sort my datagridview by cell background color . 我想按单元格背景颜色对我的datagridview进行排序。 for example : which rows that cell[1] is red , priority in first . 例如:cell [1]的哪些行是红色的,优先级在第一。 and which rows that cell is white , priority in second. 以及该单元格的哪些行是白色的(第二优先级)。

in bellow code , i change background color of cell. 在下面的代码中,我更改单元格的背景颜色。

DataGridViewCellStyle FormTypeCellStyle = new DataGridViewCellStyle();
        FormTypeCellStyle.BackColor = Color.Red;

        for (int i = 0; i < dataGridView1.RowCount; i++)
        {
            if (dataGridView1.Rows[i].Cells["FormID"].Value.ToString() != Convert.ToString(SettingVariables.FormID_NormReqFromBb))
            {
                dataGridView1.Rows[i].Cells["PersianName"].Style = FormTypeCellStyle;
            } 
        }    

now i want sort my datagridview by cell color .please help me , how do i can this ? 现在我想按单元格颜色对我的datagridview进行排序。请帮助我,我该怎么办?

您可以按照相同的条件订购数据源,设置颜色

dataGridView1.DataSource = data.OrderBy(x => x.FormID != Convert.ToString(SettingVariables.FormID_NormReqFromBb));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM