关于datagridview和checkbox 我在datagridview里面每次显示50条记录。我想像QQ邮箱里那样,每行前面有一个checkbox。可以选择我要的行。要怎么做呢。要拉50次checkbox吗。用checkedlistbox的话我拉动datagridview的滚动条,checklistbox不能跟着下。而且最后一页可能没有50条记录。该怎么做的呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1 在设计页面选中GRIDVIEW控件,单击控件右上角的三角2 点击 编辑列 。3 添加一个 BoundField 将它调整至第1个4 点击 编辑列 窗口中,右下角的蓝色连接 “将此字段转换为”TemplateField5 确定退出。6 再次执行第1步,7 点击 编辑模板8 选中 你刚才添加的那个列(经过转换后)的 ItemTemplate9 将一个 Checkbox 拖到设计页面的ItemTemplate 中。OK 你看看效果。关于数据绑定的问题,你先把上面的弄通了,我再接着回复 Columns属性里加一个DataGridView CheckBox列...放按钮实现 全选/反选 功能啊...... 用了3楼的方法。2楼说的是网页的吧。我做的是wingform。怎么确定有没有选中某一列呢。 用 Repeater 绑定数据 更加方便 确定选择行....if(datagridview1.Rows[i].Cells["列名"].Value == null){ //没选中}else{ if((bool)datagridview1.Rows[i].Cells["列名"].Value) { //选中 } else { //没选中 }} //全选/取消全选 private void checkBox1_CheckedChanged(object sender, EventArgs e) { foreach (DataGridViewRow dr in this.datagridview1.Rows) { dr.Cells["列名"].Value = checkBox1.Checked; } } //反选 private void checkBox2_CheckedChanged(object sender, EventArgs e) { foreach (DataGridViewRow dr in this.datagridview1.Rows) { if (dr.Cells["列名"].Value == null) { dr.Cells["列名"].Value = true; } else { dr.Cells["列名"].Value = !(bool)dr.Cells["列名"].Value; } } } 使用datagridviewcheckboxDataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv.Rows[i].Cells["check"]; checkCell.Value = false;dataGridView1.Rows[1].Cells[0].Value = true;foreach (DataGridViewRow dr in this.dataGridView1.Rows) { try { DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells(0); if (Convert.ToBoolean(cbx.FormattedValue)) { str += dr.Cells(1).Value; } } catch (Exception ex) { MessageBox.Show(ex.Message); }} 又碰到问题了。我的原来的列名使用 datagridview.Columns[1].HeaderCell.Value = "日期";这样的代码加上去的,我在datagridview右边的三角里点添加的checkbox列显示不出来。好像被用代码加上去的列覆盖了。 纯技术贴!思胜第一季:C# 基础 0 - 前言 如何实现LISTVIEW中把文件拖拽进文件夹的效果 VS2008 CrystalReport的教程 从DataSet或DataTable继承的类无法序列化 msde "[Share Memory]SqlServer 不存在或访问被拒绝!" 要命了! 求助一弱智问题!!! 请推荐决策支持系统开发的资料 EXCEL数据导入到ListView 我的思路是这样的。。。。。 我写错了吗?这个类到底出什么怪毛病了? 各位大虾请进!!我有急用!!马上给分!! 谁有vs安装部署视频教程 TCP通讯高手帮忙想想
2 点击 编辑列 。
3 添加一个 BoundField 将它调整至第1个
4 点击 编辑列 窗口中,右下角的蓝色连接 “将此字段转换为”TemplateField
5 确定退出。
6 再次执行第1步,
7 点击 编辑模板
8 选中 你刚才添加的那个列(经过转换后)的 ItemTemplate
9 将一个 Checkbox 拖到设计页面的ItemTemplate 中。OK 你看看效果。
关于数据绑定的问题,你先把上面的弄通了,我再接着回复
if(datagridview1.Rows[i].Cells["列名"].Value == null)
{
//没选中
}
else
{
if((bool)datagridview1.Rows[i].Cells["列名"].Value)
{
//选中
}
else
{
//没选中
}}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow dr in this.datagridview1.Rows)
{
dr.Cells["列名"].Value = checkBox1.Checked;
}
}
//反选
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow dr in this.datagridview1.Rows)
{
if (dr.Cells["列名"].Value == null)
{
dr.Cells["列名"].Value = true;
}
else
{
dr.Cells["列名"].Value = !(bool)dr.Cells["列名"].Value;
}
}
}
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dgv.Rows[i].Cells["check"];
checkCell.Value = false;
dataGridView1.Rows[1].Cells[0].Value = true;
foreach (DataGridViewRow dr in this.dataGridView1.Rows) {
try {
DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells(0);
if (Convert.ToBoolean(cbx.FormattedValue)) {
str += dr.Cells(1).Value;
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}