【发布时间】:2016-11-08 14:10:12
【问题描述】:
我想将按钮添加到 DataGridView 中的列...但有一个条件:当 ROW 的颜色为红色时, 这是数据网格视图:
现在,“结帐”列中的所有按钮都可以使用...与红色行或白色行...我的代码:
int row = (int)this.dataGridView1.CurrentCell.OwningRow.Cells[0].Value;
if (MessageBox.Show("Check-out?",
"Message de confirmation",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{ MessageBox.Show("Success!!");
}
仅按钮与 Red ROW 一起使用, 我试试这段代码:
if (dataGridView1.SelectedRows[0].DefaultCellStyle.BackColor == Color.Red)
{
int row = (int)this.dataGridView1.CurrentCell.OwningRow.Cells[0].Value;
if (MessageBox.Show("Check-out?",
"Message de confirmation",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{MessageBox.Show("Success!!");
}
我有错误:索引超出限制。它不能是负数,并且必须小于集合的大小。排队:
if (dataGridView1.SelectedRows[0].DefaultCellStyle.BackColor == Color.Red)
错误:
谢谢,
【问题讨论】:
标签: c# datagridview colors conditional-statements