DATAGridview 中增加CHECKBOX 本帖最后由 zhongdecai 于 2009-07-09 13:50:28 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一个问题,在你的数据源里面添加一列Bool类型的数据源就行了第二个可以根据条件把数据删了,在把datagridview里面的数据循环添加到数据库中,或者用sqlcommandbuilder第三个,循环判断是否选中this.datagirdview.rows[1].cells[0].value.tostring().equals("true")//选中 lsj_zrp回答的很好了, 至于DataGridView控件使用可以参考C# WinForm开发系列 - DataGridView 呵呵,web用过,估计差不多吧。 以下方法判断是否选中其中chkClient是checkbox的namepublic bool IsNoChecked() { bool temp = false; for (int count = 0; count < this.dgvCommon.Rows.Count; count++) { DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"]; if (cbh != null && (bool)cbh.FormattedValue) { temp = true; break; } } return temp; } 以下是一个删除前询问以及循环判断应该删除选中的项(一项多项都可以)public void deleteClientFun() { if (MessageBoxYesCancel("确定删除选中客户吗?删除后无法恢复!") == DialogResult.OK) { for (int count = 0; count < this.dgvCommon.Rows.Count; count++) { DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"]; if (cbh != null && (bool)cbh.FormattedValue) { 你的删除方法 } } datagridview1的重新绑定 } }最后这个是询问公共对话框public static DialogResult MessageBoxYesCancel(string Information)//通用弹出式信息显示对话框方法(进行互操作)返回黄色感汉号 { string caption = "【系统提示】"; MessageBoxButtons buttons = MessageBoxButtons.OKCancel; return MessageBox.Show(Information, caption, buttons, MessageBoxIcon.Question); } 至于你的第二个问题2,可以直接保存DATAGRIDVIEW里面的内容给你一个贴子你看看吧:http://blog.csdn.net/zushao0124/archive/2007/05/02/1594985.aspx C# winform 向Excel中插入图片问题 两个列表或者序列相加,即是在原有的列表添加一条序列 怎么用C#连接ORACLE数据库 C#,获取Arial 字体的宽度 求会员制网站系统 关于DataGridView的CellEndEdit事件的问题! 有一年asp项目经验,几个月业余时间学习.net经验,现在要你一个人开发,你会用asp还是.net 哪里有C#操作数据库的代码? c#中怎么自己来强行清空一个new出来的byte数组,急 关于在发VS.NET中用ASP访问数据库的问题? tcp socket能发不能收,这是为什么? c# 线程同步问题
第二个可以根据条件把数据删了,在把datagridview里面的数据循环添加到数据库中,或者用sqlcommandbuilder
第三个,循环判断是否选中
this.datagirdview.rows[1].cells[0].value.tostring().equals("true")//选中
其中chkClient是checkbox的namepublic bool IsNoChecked()
{
bool temp = false;
for (int count = 0; count < this.dgvCommon.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"];
if (cbh != null && (bool)cbh.FormattedValue)
{
temp = true;
break;
}
}
return temp;
}
{
if (MessageBoxYesCancel("确定删除选中客户吗?删除后无法恢复!") == DialogResult.OK)
{
for (int count = 0; count < this.dgvCommon.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"];
if (cbh != null && (bool)cbh.FormattedValue)
{
你的删除方法
}
}
datagridview1的重新绑定
}
}
最后这个是询问公共对话框public static DialogResult MessageBoxYesCancel(string Information)//通用弹出式信息显示对话框方法(进行互操作)返回黄色感汉号
{
string caption = "【系统提示】";
MessageBoxButtons buttons = MessageBoxButtons.OKCancel;
return MessageBox.Show(Information, caption, buttons, MessageBoxIcon.Question);
}
2,可以直接保存DATAGRIDVIEW里面的内容
给你一个贴子你看看吧:
http://blog.csdn.net/zushao0124/archive/2007/05/02/1594985.aspx