徐胜利

导航

C#单独改变DataGridView按钮列中某个按钮的文本

功    能:改变单个按钮的文本

注意事项:

           1,  将DataGridViewButtonColumn列属性UseColumnTextForButtonValue设为false,意为不用按钮Text属性来显示按钮文本;

           2,  将DefaultCellStyle里面属性NullValue设置为按钮文本

           3,  在DataGridView1里面CellClick事件里面添加如下代码

                 Private void DataGridView1_CellClick(Object sender,DataGridViewCellEventArgs e)

                 {

                       if(e.ColumnIndex != 按钮列索引 && e.RowIndex != -1)

                       {

                           return;

                       }

                       if(this.DataGridView1.CurrentCell.Value == null || this.DataGridView1.CurrentCell.Value.ToString() == “启用”)

                       {

                            this.DataGridView1.CurrentCell.Value = “停用”;

                       }

                       else

                       {

                             this.DataGridView1.CurrentCell.Value = “启用”;

                       }

                 }

备注:

    按钮文本默认为“启用”,点击之后设置为“停用”,根据需要,设置为相应文本。

posted on 2012-08-25 10:53  xuvictory  阅读(3174)  评论(0)    收藏  举报