【发布时间】:2014-10-01 18:24:31
【问题描述】:
我有一个 DataGridView,这是上一个问题 (link) 的主题。但有时按钮是null。这可以。但如果它为空,有什么方法可以选择删除/添加(显示/隐藏?)按钮到按钮的DataGridViewButtonColumn
像这样:
+------------+------------+
| MyText | MyButton |
+------------+------------+
| "do this" | (Yes) |
| "do that" | (Yes) |
| FYI 'blah' | | <---- this is where I optionally want no button
| "do other" | (Yes) |
+------------+------------+
这是我迄今为止尝试过的 (based on this example)
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;
}
}
}
【问题讨论】:
-
按钮应该用什么代替?
-
只是一片空白……根本没有按钮
-
保持简单 - 将其设置为 null 并忽略它被点击..
标签: c# datagridview visibility datagridviewbuttoncolumn