//加入ItemCheck方法
this.cblChangeMode.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.SelectOne);
//加入控制是否继续的全局变量,防止进入死循环
public bool canContinue = true;
private void SelectOne(object sender, ItemCheckEventArgs e)
{
CheckedListBox clb = sender as CheckedListBox;
//勾选原选项
if (clb.CheckedIndices.Count > 0 && clb.CheckedIndices[0] == e.Index && canContinue )
{
e.NewValue = CheckState.Checked;
}
//第一次勾选
else if (clb.CheckedIndices.Count == 0)
{
canContinue = true;
}
//勾选新选项
else if (clb.CheckedIndices.Count > 0 && clb.CheckedIndices[0] != e.Index)
{
canContinue = fal
C# WinForm CheckedListBox实现RadioButton的单选且不可取消单选的效果
最新推荐文章于 2024-04-05 10:15:20 发布