.Net的DataGridView控件中,提供了一种列的类型,叫
在正式开始介绍使用方法之前,我们先要进行一个概念性的说明:
DataGridViewButtonColumn
今天,我们先来说一下,如何根据需要动态改变某个button显示的文本
程序实现的效果图如下
实现的步骤:
给DataGridView添加一列 DataGridViewButtonColumn
UseColumnTextForButtonVa
其他属性自己根据需要设置
在DataGridView的CellContentClick事件中,写入如下的类似代码:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArg
{
//注释:
//dataGridView1.Columns[e.ColumnIndex] is DataGridViewButtonColumn
// e.RowIndex > -1 ,说明点击的不是列头
if (dataGridView1.Columns[e.ColumnIndex] is DataGridViewButtonColumn
{
//获取当前被点击的单元格 DataGridViewButtonCell vCell = (DataGridViewButtonCell)dataGridView1.CurrentCell; if (vCell.Tag == null) { vCell.Value = “停用”; vCell.Tag = true; }
}
}
原文地址:http://hi.baidu.com/322yali/item/2161772eb685360c72863ed4