I have a DataGridView
which was the subject of a previous question (link). But sometimes the Button is null
. This is fine. But if it is null, is there any way I can optionally remove/add (show/hide?) buttons to the DataGridViewButtonColumn
of Buttons
like this:
+------------+------------+
| MyText | MyButton |
+------------+------------+
| "do this" | (Yes) |
| "do that" | (Yes) |
| FYI 'blah' | | <---- this is where I optionally want no button
| "do other" | (Yes) |
+------------+------------+
this is what I have tried so far (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;
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…