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