希望winform中的datagridview中的复选框,能够选中指定数量的做法
2012-09-21 10:47
274 查看
1.首先将datagridview的属性的readonly改为ture
2.代码
datagridview:
private void datagridview1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
if (this.dgvInfo.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString() == "False")
{
this.dgvInfo.Rows[e.RowIndex].Cells[0].Value = ture;
iChkedCount++;
}
else
{
this.dgvInfo.Rows[e.RowIndex].Cells[0].Value = false;
iChkedCount--;
}
if (iChkedCount > 5)
{
iRowSelect = e.RowIndex;
timer2.Interval = 100;
timer2.Enabled = true;
}
else
ShowSelCount("最多选择5种,已经选择" + iChkedCount.ToString() + "种");
}
}
定时器:
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Enabled = false;
if (iChkedCount > 5)
{
this.dgvInfo.Rows[iRowSelect].Cells[0].Value = false;
iChkedCount--;
ShowSelCount("最多选择5种,已经选择" + iChkedCount.ToString() + "种");
dgvInfo.Refresh();
}
2.代码
datagridview:
private void datagridview1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
if (this.dgvInfo.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString() == "False")
{
this.dgvInfo.Rows[e.RowIndex].Cells[0].Value = ture;
iChkedCount++;
}
else
{
this.dgvInfo.Rows[e.RowIndex].Cells[0].Value = false;
iChkedCount--;
}
if (iChkedCount > 5)
{
iRowSelect = e.RowIndex;
timer2.Interval = 100;
timer2.Enabled = true;
}
else
ShowSelCount("最多选择5种,已经选择" + iChkedCount.ToString() + "种");
}
}
定时器:
private void timer2_Tick(object sender, EventArgs e)
{
timer2.Enabled = false;
if (iChkedCount > 5)
{
this.dgvInfo.Rows[iRowSelect].Cells[0].Value = false;
iChkedCount--;
ShowSelCount("最多选择5种,已经选择" + iChkedCount.ToString() + "种");
dgvInfo.Refresh();
}
相关文章推荐
- [WinForm]DataGridView选中一行获取指定单元格的值
- [WinForm]DataGridView选中一行获取指定单元格的值
- C# WinForm 设置DataGridView选中指定行
- 让dataGridView中的复选框选中(winform)
- 上接扩展GridView控件(7) - 行的指定复选框选中时改变行的样式
- jQuery实现统计复选框选中数量
- jQuery实现统计复选框选中数量
- 扩展GridView控件(7) - 行的指定复选框选中时改变行的样式
- dataGridView空白列,默认选中行的背景色,dataGridView中加入复选框勾选状态的更改
- C# winform打开文件夹并选中指定文件
- 扩展GridView控件(7) - 行的指定复选框选中时改变行的样式
- C#Winform基础 显示选中的行是第几行,datagridview控件
- WinForm DataGridView 鼠标点击选中整行
- 【JQuery】jquery获取用户选中的复选框数量
- WinForm中DataGridView控件通过复选框实现多条记录的删除 c#2005
- dataGridView空白列,默认选中行的背景色,dataGridView中加入复选框勾选状态的更改
- winform中datagridview 在单元格选中状态下(非编辑状态)输入一个字符产生重复的问题
- treeview(winform)里如何用命令指定选中某一个节点,并引发afterselect事件?
- winform 取消datagridview第一行选中状态
- 利用winform中DataGridView的显示较大数量的的数据