简体   繁体   中英

how do i sort datagridview by cell color?

i want to sort my datagridview by cell background color . for example : which rows that cell[1] is red , priority in first . 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 ?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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