我想更新这个DataGridView对象,使得如果一个值==“bob”的名字旁边会有一个按钮,否则我不想出现任何按钮。如何将按钮添加到我的DataGridView中的某些列(不是全部)?
DataGridViewTextBoxColumn valueColumn = new DataGridViewTextBoxColumn();
DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn();
buttonColumn.ReadOnly = true;
buttonColumn.Visible = false;
this.dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
valueColumn,
buttonColumn,
});
//elsewhere...
if(value == "bob")
{
Button button = new Button()
{
Text = "null",
};
index = dgv.Rows.Add(value, button);
DataGridViewButtonCell buttonCell = dgv.Rows[index].Cells[2] as DataGridViewButtonCell;
buttonCell.Visible = true;
}
else
{
dgv.Rows.Add(value);
}
但是,由于我无法在单元格上设置Visible,因此这不起作用。有没有一种方法来添加一个按钮,只有行的值是==“bob”?