展会信息港展会大全

实现DataGridView控件中CheckBox列的使用实例
来源:互联网   发布日期:2015-10-03 10:47:25   浏览:1363次  

导读:最近做WindowsForms程序,使用DataGridView控件时,加了一列做选择用,发现CheckBox不能选中。搜索后,要实现 DataGridView的CellContentClick事件,将代码贴一下代码如下: summary 实现Data ...

最近做WindowsForms程序,使用DataGridView控件时,加了一列做选择用,发现CheckBox不能选中。搜索后,要实现 DataGridView的CellContentClick事件,将代码贴一下

代码如下:

/// <summary>

/// 实现DataGridView控件中CheckBox列的使用

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void dgvTradList_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

if (e.ColumnIndex == 0 && e.RowIndex != -1)

{

if ((bool)dgvTradList.Rows[e.RowIndex].Cells[0].EditedFormattedValue == true)

{

dgvTradList.Rows[e.RowIndex].Cells[0].Value = false;

}

else

{

dgvTradList.Rows[e.RowIndex].Cells[0].Value = true;

}

}

赞助本站

人工智能实验室

相关热词: CheckBox DataGridView

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港