您的位置:首页 > 其它

希望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();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: