i have a data gridview with 4 columns first 2 columns are combobox columns, third column is textbox column and 4th column is button column.In form load i have to disable the entire button column of datagrid and after this i should select first three columns and save these first three columns in database after saving this the button column in the particular row should enable.first three columns should be saved in databese by clicking a button.
Please help me im struck up with this problem from many days
here is the code which i used
private void SATAddTemplate_Load(object sender, EventArgs e)
{
foreach (DataGridViewRow row in datagrdADDTEMP.Rows)
{
DataGridViewButtonCell btn = (DataGridViewButtonCell)row.Cells[3];
btn.ReadOnly = true;
}
}
private void btnSaveSettings_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in datagrdADDTEMP.Rows)
{
DataGridViewButtonCell btn = (DataGridViewButtonCell)row.Cells[3];
btn.ReadOnly = false;
}
}
Here’s some help with the problem of setting the
Enabledproperty of the Buttons that appear in aDataGridViewButtonColumn.You’ll need to extend
DataGridViewButtonColumnto create your own DataGridView column with disable-able buttons. This article on MSDN details how to do this.The article has a lot of code, and I encourage you to take a close look, but all you really need to do is copy and paste into your project the following classes found in the article:
— DataGridViewDisableButtonColumn
— DataGridViewDisableButtonCell
Once you do this you will be able to add
DataGridViewDisableButtonColumns to your DataGridView. Use the publicEnabledproperty exposed in your custom column to set theEnabledproperty of each cell’s Button control. Since you want to set theEnabledproperty of all the Buttons in the column you can write a helper method that loops through all rows in your DataGridView and sets theEnabledproperty: