条件格式单元格c#
本文关键字:单元格 格式 条件 | 更新日期: 2023-09-27 18:29:57
我该如何将格式应用于此网格,如果状态=已保存,我希望格式化网格视图中的单元格,我希望此文本显示为红色,因此它更引人注目
// setup columns
this.grid1.Cell(0, 0).Text = "ID";
this.grid1.Cell(0, 1).Text = "Scrap Code";
this.grid1.Cell(0, 2).Text = "Station";
this.grid1.Cell(0, 3).Text = "Operator";
this.grid1.Cell(0, 4).Text = "Product";
this.grid1.Cell(0, 5).Text = "Status";
this.grid1.Cell(0, 6).Text = "Date Logged";
this.grid1.Cell(0, 7).Text = "Die";
this.grid1.Cell(0, 8).Text = "Core Print";
this.grid1.Cell(0, 9).Text = "Stamp";
this.grid1.Cell(0, 10).Text = "Line";
this.grid1.Cell(0, 11).Text = "Grid Ref";
this.grid1.Cell(0, 12).Text = "Cast Date";
this.grid1.Cell(0, 13).Text = "Shift";
this.grid1.Cell(0, 14).Text = "Cast Hour";
this.grid1.Column(14).Alignment = FlexCell.AlignmentEnum.CenterCenter;
for (int i=0; i<arrData.Count; i++)
{
string[] theData = arrData[i].ToString().Split(''t');
this.grid1.Cell(i + 1, 0).Text = theData[0];
this.grid1.Cell(i + 1, 1).Text = theData[5];
this.grid1.Cell(i + 1, 2).Text = theData[1];
this.grid1.Cell(i + 1, 3).Text = theData[2];
this.grid1.Cell(i + 1, 4).Text = theData[11];
this.grid1.Cell(i + 1, 5).Text = theData[3];
this.grid1.Cell(i + 1, 6).Text = theData[4].Replace("T", " "); ;
this.grid1.Cell(i + 1, 7).Text = theData[6];
this.grid1.Cell(i + 1, 8).Text = theData[12];
this.grid1.Cell(i + 1, 9).Text = theData[13];
this.grid1.Cell(i + 1, 10).Text = theData[14];
this.grid1.Cell(i + 1, 11).Text = theData[7];
this.grid1.Cell(i + 1, 12).Text = theData[16].Replace("T", " "); ;
this.grid1.Cell(i + 1, 13).Text = theData[15];
this.grid1.Cell(i + 1, 14).Text = theData[17];
}
为什么不试试这个
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string RowType = row.Cells[cellnumberofstatus].Value.ToString();
if (RowType == "saved")
{
row.DefaultCellStyle.BackColor = Color.White;
row.DefaultCellStyle.ForeColor = Color.Red;
}
}
为什么不试试这个
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string RowType = row.Cells[cellnumberofstatus].Value.ToString();
if (RowType == "saved")
{
row.DefaultCellStyle.BackColor = Color.White;
row.DefaultCellStyle.ForeColor = Color.Red;
}
}
编辑:尝试这个
if(dataGridView1.Rows[h].Cells[number].Value == "saved")
dataGridView1.Rows[h].DefaultCellStyle.ForeColor = Color.Red;