Hiding a Button in a DataGridView
-
I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview. Any help would be appreciated. Thanks John
-
I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview. Any help would be appreciated. Thanks John
For that you need to use RowDataBound event. Try following code.
protected void MyDataGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (condition)
{
(e.Row.FindControl("buttonid") as Button).Enabled = false;
}
}
}HTH
Jinal Desai - LIVE Experience is mother of sage....
-
I have a DataGridView in a windows form that I need to be able to make the datagridviewbutton visible or invisible depending on the value of another column. I can not figure out how to make this happen when I bind the datatable to the datagridview. Any help would be appreciated. Thanks John
hi man, this could be a possible solution but never tested.. In the CellValueChanged event you have to check your specified cell against your condition and than try:
dataGridView1.Rows[rowIndex].Cells[buttonCell].ReadOnly = true;
ordataGridView1.Rows[rowIndex].Cells[buttonCell].Frozen = true;
hope i could help :)