DataGridView动态显示button

happy366day 2012-11-05 05:05:03
WinForm程序:
根据这一行记录的列的值,来动态设置button.text的值,button是在DataGridView最后一列

如:
DataGridView记录中,第一行useStatus这一列是0 ,那么button的text属性设置成"1"
第2行useStatus这一列是1 ,那么button的text属性设置成"0"
...全文
147 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pennymay 2012-11-05
  • 打赏
  • 举报
回复
添加一个FOR EACH 事件

foreach (DataGridViewRow row in this.dataGridView1.Rows)
{                            
    foreach (DataGridViewCell cell in row.Cells)
    {
        if (cell.Size.IsEmpty)
        {
            if useStatus== 0
            button.text=1
            else if useStatus== 1
            button.text=0
        }
        
    }
}
linsiyong1 2012-11-05
  • 打赏
  • 举报
回复
添加一个事件RowPrePaint 随后再描画的时候控制下button的显示值 private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { DataGridViewButtonCell btn =(this.dataGridView1.Rows[e.RowIndex].Cells[1]) as DataGridViewButtonCell; DataGridViewTextBoxCell text = (this.dataGridView1.Rows[e.RowIndex].Cells[0]) as DataGridViewTextBoxCell; btn.Value = text.Value; }

111,122

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧