c#中datagridview里checkbox的使用方法[转]
view plaincopy to clipboardprint?
1、屬性設(shè)置checkboxcolumn??
?
name:cb_check???????
falsevalue:false??????
truevalue:true?
datagridview中的readonly設(shè)置為false.??
?
2、? //單項(xiàng)選擇設(shè)置??
private void dgv_zy_CellContentClick(object sender, DataGridViewCellEventArgs e)??
??????? {??
??????????? int count = Convert.ToInt16(dgv_zy.Rows.Count.ToString());??
??????????????????? for (int i = 0; i < count; i++)??
{???
{??
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv_zy.Rows[i].Cells["cb_check"];?? {???
??????????????? Boolean flag = Convert.ToBoolean(checkCell.Value);??
??????????????? if (flag == true)???? //查找被選擇的數(shù)據(jù)行??
??????????????? {??
??????????????????? checkCell.Value = false;??
??????????????? }??
??????????????????? continue;??
???????????? }??
??????? }??
?
???
?
3、獲取選擇的數(shù)據(jù)??
??????????? int count = Convert.ToInt32(dgv_zy.Rows.Count.ToString());??
??????????? for (int i = 0; i < count; i++)??
??????????? {??
?????????????? //如果DataGridView是可編輯的,將數(shù)據(jù)提交,否則處于編輯狀態(tài)的行無法取到??
????????????????????? dgv_zy.EndEdit();??
??????????????? DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv_zy.Rows[i].Cells["cb_check"];??
??????????????? Boolean flag = Convert.ToBoolean(checkCell.Value);??
?????????????? if (flag == true)???? //查找被選擇的數(shù)據(jù)行??
??????????????? {??
??????????????????? //從 DATAGRIDVIEW 中獲取數(shù)據(jù)項(xiàng)??
?????????????? string z_zcode = dgv_zy.Rows[i].Cells[0].Value.ToString().Trim();??
????????????? //........................................??????????????? }??
???????? }?
本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/songkexin/archive/2009/12/03/4934143.aspx
posted on 2010-09-02 08:12 guofu 閱讀(...) 評(píng)論(...) 編輯 收藏轉(zhuǎn)載于:https://www.cnblogs.com/saptechnique/archive/2010/09/02/1815626.html
總結(jié)
以上是生活随笔為你收集整理的c#中datagridview里checkbox的使用方法[转]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国最闷声发大财的城市,人均GDP超杭州
- 下一篇: 两则新闻