開發(fā)(winform)時碰到這個問題 C# 怎樣判斷 datagridview 中的checkbox列是否被選中,錯誤原因都C#對類型判斷相當嚴格,為了避免大家以后多走彎路,把我的思路和大家說一下,希望對大家有幫助。
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue==true)
{
//TODO
}
}
if ($ != jQuery) { $ = jQuery.noConflict(); } var isLogined = true; var cb_blogId = 67609; var cb_entryId = 1768554; var cb_blogApp = "tianguook"; var cb_blogUserGuid = "26710bb1-fd2c-df11-ba8f-001cf0cd104b"; var cb_entryCreatedDate = '2010/6/30 18:45:00';
==========================================
private void PrintInFo() {
try
{
int count = 0;
//用于保存選中的checkbox數(shù)量
//DG_List為datagridview控件
for (int i = 0; i < DG_List.RowCount; i++)
{
if (DG_List.Rows[i].Cells [0].EditedFormattedValue.ToString() == "True")
//這里判斷復選框是否選中
{
count++;
}
}
if (count == 0)
{
MessageBox.Show("請至少選擇一條數(shù)據(jù)!", "提示");
return;
}
else
{
if (MessageBox.Show(this, "您要更新數(shù)據(jù)么?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information).ToString() == "Yes")
{
for (int i = 0; i < count; i++)
{
ps.Pexcute(" update cf_prj_certi set FIsPrint='"+number+"' where fid='" + DG_List.Rows[i].Cells["fnn"].Value.ToString() + "'"); //執(zhí)行SQL
}
} else
{
return;
}
}
} catch (Exception ex)
{
MessageBox.Show(ex.ToString());
} this.ShowInfo(); //重新綁定datagridview
}
=========================================
點擊dataGridView1事件中的CellMouseClick 事件
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if(e.ColumnIndex==6)
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;
}
}
if ($ != jQuery) { $ = jQuery.noConflict(); } var isLogined = true; var cb_blogId = 67609; var cb_entryId = 1768554; var cb_blogApp = "tianguook"; var cb_blogUserGuid = "26710bb1-fd2c-df11-ba8f-001cf0cd104b"; var cb_entryCreatedDate = '2010/6/30 18:45:00';
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答!! 點擊進入論壇