我有一个datagridview由5行组成,如下所示:
int number = dataGridView1.Rows.Add();
dataGridView1.Rows[number].Cells[0].Value = result;
dataGridView1.Rows[number].Cells[1].Value = newAddress;
dataGridView1.Rows[number].Cells[2].Value = (string)((Hashtable)ht[1])["value"];
dataGridView1.Rows[number].Cells[3].Value = (string)((Hashtable)ht[2])["value"];
dataGridView1.Rows[number].Cells[4].Value = (string)((Hashtable)ht[3])["value"];
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[4].Value.ToString() == "")
{
row.Cells[5].Visible = false; //error
}
}
单元格5是保存按钮。现在我想检查单元格号4是否为空,然后将单元格5的可见性设置为false(隐藏按钮)。但是,我在注释行中收到此错误。
Property or indexer 'System.Windows.Forms.DataGridViewCell.Visible' cannot be assigned to -- it is read only
我已经检查了datagridview1和列readonly属性,它都被设置为false。但我仍然面临这个错误。
有人可以提供建议吗?