我有一个带有数据的datagridview,数据行被着色(仅文本着色)如下:红色,橙色和黑色例如:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
switch (e.Value.ToString())
{
case "SDP":
e.Value = "Schedule Departure";
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
break;
case "CKN":
e.Value = "Check-In";
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Orange;
break;
case "P2G":
e.Value = "Proceed to Gate";
this.dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Black;
break;
}
我还创建了带有几个单选按钮的 Groupbox 来更改排序
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
ListSortDirection direction;
direction = ListSortDirection.Ascending;
dataGridView1.Sort(arrTimeDataGridViewTextBoxColumn,direction);
}
但问题是:如何根据文本的颜色更改排序,例如:RED, ORANGE then Black?