![](/img/trans.png)
[英]how do i convert or display the color base on the color code inside the datagridview cell?
[英]how do i sort datagridview by cell color?
我想按單元格背景顏色對我的datagridview進行排序。 例如:cell [1]的哪些行是紅色的,優先級在第一。 以及該單元格的哪些行是白色的(第二優先級)。
在下面的代碼中,我更改單元格的背景顏色。
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;
}
}
現在我想按單元格顏色對我的datagridview進行排序。請幫助我,我該怎么辦?
您可以按照相同的條件訂購數據源,設置顏色
dataGridView1.DataSource = data.OrderBy(x => x.FormID != Convert.ToString(SettingVariables.FormID_NormReqFromBb));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.