首页 > Windows开发 > 详细

Datagridview 添加checkbox列,并判断Datagridview 中的checkbox列是否被选中

时间:2016-09-04 23:50:19      阅读:271      评论:0      收藏:0      [点我收藏+]

Solution1:
//In Fill DataGridViewEvent :

DataGridViewCheckBoxColumn ChCol = new DataGridViewCheckBoxColumn();
ChCol.Name = "CheckBoxRow";
ChCol.HeaderText = "CheckboxSelection";
ChCol.Width = 50;
ChCol.TrueValue = "1";
ChCol.FalseValue = "0";
datagridview_tabpage1.Columns.Insert(0, ChCol);

// In Button Event put these codes:

datagridview 中的checkbox列是否被选中

private void button3_Click(object sender, EventArgs e)
{
string selectRows="";
for (int i = 0; i < dataGridView_tabPage1.Rows.Count - 1; i++) //循环datagridview每行
{
if ((bool)dataGridView_tabPage1.Rows[i].Cells[0].EditedFormattedValue == true)
{
selectRows = selectRows + "[" + i.ToString() + "]";

}
}

MessageBox.Show("Selected Rows:" + selectRows,"CheckBoxRows");

}

add check box in Datagridview
   // Initialize and add a check box column.
            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column = new DataGridViewCheckBoxColumn();
            column.DataPropertyName = "selection";
            column.Name = "selection";
            dataGridView_tabPage1.Columns.Add(column);

 



 

 

 



Datagridview 添加checkbox列,并判断Datagridview 中的checkbox列是否被选中

原文:http://www.cnblogs.com/noteswiki/p/5840578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!