我可以在 windows 表单数据网格视图工具中添加状态栏吗?
can I add a status bar in a windows form data grid view tool?
我想在类似这样的数据网格视图工具中添加一个状态栏。
是否可以添加这样的栏目?如果不能,我可以为这种事情做些什么?
您可以尝试根据您特定列中的条件设置单元格的背景颜色。
这是一个代码示例,您可以参考。
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Columns.Add("col1", "Name");
dataGridView1.Columns.Add("col2", "Age");
dataGridView1.Columns.Add("col3", "Status");
dataGridView1.Rows.Add("test1", 22, "Normal");
dataGridView1.Rows.Add("test2", 23, "Risk");
dataGridView1.Rows.Add("test3", 26, "Abnormal");
for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
{
string value = dataGridView1.Rows[i].Cells[2].Value.ToString();
switch (value)
{
case "Normal":
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Green;
break;
case "Risk":
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Red;
break;
case "Abnormal":
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Blue;
break;
default:
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.White;
break;
}
}
}
结果:
我想在类似这样的数据网格视图工具中添加一个状态栏。
是否可以添加这样的栏目?如果不能,我可以为这种事情做些什么?
您可以尝试根据您特定列中的条件设置单元格的背景颜色。
这是一个代码示例,您可以参考。
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Columns.Add("col1", "Name");
dataGridView1.Columns.Add("col2", "Age");
dataGridView1.Columns.Add("col3", "Status");
dataGridView1.Rows.Add("test1", 22, "Normal");
dataGridView1.Rows.Add("test2", 23, "Risk");
dataGridView1.Rows.Add("test3", 26, "Abnormal");
for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
{
string value = dataGridView1.Rows[i].Cells[2].Value.ToString();
switch (value)
{
case "Normal":
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Green;
break;
case "Risk":
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Red;
break;
case "Abnormal":
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.Blue;
break;
default:
dataGridView1.Rows[i].Cells[2].Style.BackColor = Color.White;
break;
}
}
}
结果: