Here's some help with the problem of setting the Enabled
property of the Buttons that appear in a DataGridViewButtonColumn
.
You'll need to extend DataGridViewButtonColumn
to 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 DataGridViewDisableButtonColumn
s to your DataGridView. Use the public Enabled
property exposed in your custom column to set the Enabled
property of each cell's Button control. Since you want to set the Enabled
property of all the Buttons in the column you can write a helper method that loops through all rows in your DataGridView and sets the Enabled
property:
private void SetDGVButtonColumnEnable(bool enabled) {
foreach (DataGridViewRow row in dataGridView1.Rows) {
// Set Enabled property of the fourth column in the DGV.
((DataGridViewDisableButtonCell)row.Cells[3]).Enabled = enabled;
}
dataGridView1.Refresh();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…