110,502
社区成员
发帖
与我相关
我的任务
分享
//绑定dataGridView的数据源
foreach (DataGridViewRow row in dataGridView1.Rows)
{
//假设第0列为金额,第1列为收款人,第2列为收款时间
//收款人和收款时间一起取出,绑定到dataGridView,但设它的Visible为false,让其不可见
row.Cells[0].ToolTipText = "收款人:" + row.Cells[1].Value.ToString() + "\n收款时间:" + row.Cells[2].Value.ToString();
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() == "1")//判断当前行第1个单元格的值是不是为1
{
e.CellStyle.BackColor = Color.Red;
}
//.....通过if或switch判断不同的状态,显示不同的颜色
}