DataGridViewCheckBoxColumn的勾选框勾上了,Value却是false
2013-04-25 15:24
246 查看
private void dgvWebSiteOrder_CellClick(object sender, DataGridViewCellEventArgs e)
{
//此事件里面不能获取 if (row.Cells[this.colSelect.Name].Value != null && row.Cells[this.colSelect.Name].Value.ToString() == "1")
}
private void dgvLinkOrderList_CellContentClick(object sender, DataGridViewCellEventArgs e) { //此事件里面不能获取 if (e.ColumnIndex < 0 || e.RowIndex < 0)
{
return;
} }
//此事件里面可以获取 private void dgvWebSiteOrder_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
List<DataGridViewRow> selectRows = new List<DataGridViewRow>();
//点击的是第一列。
if (e.ColumnIndex == 0)
{
foreach (DataGridViewRow row in this.dgvWebSiteOrder.Rows)
{
if (row.Cells[this.colSelect.Name].Value != null && row.Cells[this.colSelect.Name].Value.ToString() == "1")
{
selectRows.Add(row);
}
}
}
DgvSelectRows = selectRows;
}
本文转载http://www.cnblogs.com/gossip/archive/2008/12/02/1346047.htmldatagridview的checkbox列,当修改checkbox状态时实时获得其状态值
不知道大家有没有这样的经验,当点击或者取消datagridview的checkbox列时,比较难获得其状态是选中还是未选中,进而不好进行其它操作,下面就列出它的解决办法:
主要用到了datagridview的CurrentCellDirtyStateChanged和CellValueChanged两个事件
CurrentCellDirtyStateChanged事件是提交对checkbox状态的修改
CellValueChanged事件是当状态提交后,也就是单元格值改变后做一些其它的操作,这里是将checkbox列的true或false状态作为tooptiptext属性设置到同一行的button列
CurrentCellDirtyStateChanged事件代码 :
Code
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name.Equals("gender"))
{
DataGridViewButtonCell dgvButtonCell = this.dataGridView1.Rows[e.RowIndex].Cells["btn"] as DataGridViewButtonCell;//获得button列单元格
DataGridViewCheckBoxCell dgvCheckBoxCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;//获得checkbox列单元格
dgvButtonCell.ToolTipText = dgvCheckBoxCell.Value.ToString();//赋值
}
}
{
//此事件里面不能获取 if (row.Cells[this.colSelect.Name].Value != null && row.Cells[this.colSelect.Name].Value.ToString() == "1")
}
private void dgvLinkOrderList_CellContentClick(object sender, DataGridViewCellEventArgs e) { //此事件里面不能获取 if (e.ColumnIndex < 0 || e.RowIndex < 0)
{
return;
} }
//此事件里面可以获取 private void dgvWebSiteOrder_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
List<DataGridViewRow> selectRows = new List<DataGridViewRow>();
//点击的是第一列。
if (e.ColumnIndex == 0)
{
foreach (DataGridViewRow row in this.dgvWebSiteOrder.Rows)
{
if (row.Cells[this.colSelect.Name].Value != null && row.Cells[this.colSelect.Name].Value.ToString() == "1")
{
selectRows.Add(row);
}
}
}
DgvSelectRows = selectRows;
}
本文转载http://www.cnblogs.com/gossip/archive/2008/12/02/1346047.htmldatagridview的checkbox列,当修改checkbox状态时实时获得其状态值
不知道大家有没有这样的经验,当点击或者取消datagridview的checkbox列时,比较难获得其状态是选中还是未选中,进而不好进行其它操作,下面就列出它的解决办法:
主要用到了datagridview的CurrentCellDirtyStateChanged和CellValueChanged两个事件
CurrentCellDirtyStateChanged事件是提交对checkbox状态的修改
CellValueChanged事件是当状态提交后,也就是单元格值改变后做一些其它的操作,这里是将checkbox列的true或false状态作为tooptiptext属性设置到同一行的button列
CurrentCellDirtyStateChanged事件代码 :
Code
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name.Equals("gender"))
{
DataGridViewButtonCell dgvButtonCell = this.dataGridView1.Rows[e.RowIndex].Cells["btn"] as DataGridViewButtonCell;//获得button列单元格
DataGridViewCheckBoxCell dgvCheckBoxCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;//获得checkbox列单元格
dgvButtonCell.ToolTipText = dgvCheckBoxCell.Value.ToString();//赋值
}
}
相关文章推荐
- winformDatagridviev dataGridViewCheckBoxColumn关于TrueValue的问题
- DataGridView的复选框列的选中事件:DataGirdCheckBoxColumn 列 选中 事件。
- DataGridView 的 DataGridViewCheckBoxColumn使用简单说明
- Winform DataGridView CheckBoxColumn c# 单选 解决方案
- 在DataGridView中获得DataGridViewCheckBoxColumn的状态
- DataGridViewCheckBoxColumn小结
- 取 DataGridViewCheckBoxColumn 的值
- DataGridView的DataGridViewCheckBoxColumn使用方法
- Winform中DataGridView的DataGridViewCheckBoxColumn使用方法(选中与选不中)
- 获得DataGridViewCheckBoxColumn的状态
- DataGridViewCheckBoxColumn值绑定问题 -个人感觉不怎么完美
- DataGridView的DataGridViewCheckBoxColumn使用方法
- 05 trigger the checkbox column in datagridview
- c# DataGridView 中对 DataGridViewCheckBoxColumn 的操作
- DataGridViewCheckBoxColumn使用简单说明
- 全选DataGridView中的DataGridViewCheckBoxColumn选项
- DataGridViewDisableCheckBoxColumn
- C# Winform中DataGridView绑定后DataGridViewCheckBoxColumn无法显示的问题
- DataGridView DataGridViewCheckBoxColumn编辑时实时触发事件
- 获得DataGridViewCheckBoxColumn的状态