我有一个DataGridView
这是上一个问题的主题(链接)。但有时 Button 是null
. 这可以。但如果它为空,有什么方法可以选择删除/添加(显示/隐藏?)按钮到DataGridViewButtonColumn
按钮
像这样:
+------------+------------+
| MyText | MyButton |
+------------+------------+
| "do this" | (Yes) |
| "do that" | (Yes) |
| FYI 'blah' | | <---- this is where I optionally want no button
| "do other" | (Yes) |
+------------+------------+
这是我迄今为止尝试过的(基于这个例子)
private void grdVerdict_CellFormat(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == grdChoice.Columns["yesbutton"].Index)
{
if (grdVerdict[e.ColumnIndex, e.RowIndex].Value == null)
{
//grdVerdict[e.ColumnIndex, e.RowIndex].Visible = false; //<-says 'it is read only'
//grdVerdict[e.ColumnIndex, e.RowIndex].Value = new DataGridTextBox(); //<- draws 'mad red cross' over whole grid
//((Button)grdVerdict[e.ColumnIndex, e.RowIndex]).Hide; //<- won't work
}
else
{
e.Value = ((Button)grdChoice[e.ColumnIndex, e.RowIndex].Value).Text;
}
}
}