日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# Winform中DataGridView的DataGridViewCheckBoxColumn CheckBox选中判断

發布時間:2025/3/13 C# 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# Winform中DataGridView的DataGridViewCheckBoxColumn CheckBox选中判断 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、DataGridViewCheckBoxColumn CheckBox是否選中

在判斷DataGridView中CheckBox選中列的時候,用DataGridViewRow.Cells[0].FormattedValue.ToString()=="True"語句時存在問題,當我們直接點 擊CheckBox時,結果顯示未選中,但是如果我們在點擊其他單元格時,結果顯示選中。而用DataGridViewRow.Cells[0].EditedFormattedValue.ToString()=="True"語句時不管怎么樣 是選中的狀態。

為什么會有這種結果?

  原因:就是FormattedValue是操作提交后的結果,而EditedFormattedValue是當前的結果,不管結果是否已經提交。

  所以用DataGridViewRow.Cells[0].EditedFormattedValue.ToString()=="True"判斷選中比較合適

DataGridViewCheckBoxColumn 設置CheckBox默認選中

   ((DataGridViewCheckBoxCell)dgvDownloadList.Rows[i].Cells["Column1"]).Value = true;

1 if (dgvDownloadList.Rows.Count > 0) 2 { 3 for (int i = 0; i < dgvDownloadList.Rows.Count; i++) 4 { 5 string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString(); 6 if (_selectValue == "True") 7 //如果CheckBox已選中,則在此處繼續編寫代碼 8 } 9 }

?

2、DataGridViewCheckBoxColumn 第一時間獲取CheckBox的選中狀態

  當點擊或者取消datagridview的checkbox列時,比較難獲得其狀態是選中還是未選中,進而不好進行其它操作,下面就列出它的解決辦法:

  CommitEdit :將當前單元格中的更改提交到數據緩存,但不結束編輯模式?

1 dgvDownloadList.CurrentCellDirtyStateChanged += new EventHandler(dgvDownloadList_CurrentCellDirtyStateChanged); 2 dgvDownloadList.CellValueChanged += new DataGridViewCellEventHandler(dgvDownloadList_CellValueChanged); 3 4 void dgvDownloadList_CurrentCellDirtyStateChanged(object sender, EventArgs e) 5 { 6 if (dgvDownloadList.IsCurrentCellDirty) 7 { 8 dgvDownloadList.CommitEdit(DataGridViewDataErrorContexts.Commit); 9 } 10 } 11 12 void dgvDownloadList_CellValueChanged(object sender, DataGridViewCellEventArgs e) 13 { 14 if (dgvDownloadList.Rows.Count > 0) 15 { 16 for (int i = 0; i < dgvDownloadList.Rows.Count; i++) 17 { 18 string _selectValue = dgvDownloadList.Rows[i].Cells["Column1"].EditedFormattedValue.ToString(); 19 if (_selectValue == "True") 20 //如果CheckBox已選中,則在此處繼續編寫代碼 21 } 22 } 23 }

?轉載:http://blog.csdn.net/yhj821129/article/details/6290899#

?

  

轉載于:https://www.cnblogs.com/SnailWalk/p/4727988.html

總結

以上是生活随笔為你收集整理的C# Winform中DataGridView的DataGridViewCheckBoxColumn CheckBox选中判断的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。