If CheckedListBox1.CheckedItems.Count > 2 Then
            MessageBox.Show("不能选了")
        End If

解决方案 »

  1.   

    先将CheckBoxList1的AutoPostBack属性设置为true;
    再:
    private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    int count=0;
    for (int i=0;i<5;i++)
    {
    if (CheckBoxList1.Items[i].Selected==true)
    {
    count++;
    }
    if (count>=2)
    {
    CheckBoxList1.Enabled=false;
    }
    }

    }
      

  2.   

    好像没有CheckedItems这个属性啊
      

  3.   

    to jjccc
    我写了一个测试程序,把CheckBoxList1的AutoPostBack属性设置为true了,但是显示的时候无法取得x的值啊
    测试程序:
    string x = "";
    private void Button1_Click(object sender, System.EventArgs e)
    {
       Label1.Text=x;
    }private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    int count=0; 
    for(int i=0;i<5;i++)
    {
       if(CheckBoxList1.Items[i].Selected)
       {
             x=CheckBoxList1.Items[i].Text+" and  "+x;
    count++;
    if(count>1)
                       {CheckBoxList1.Enabled=false;}
       }
             }

    }
      

  4.   

    先将CheckBoxList1的AutoPostBack属性设置为true;private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    int num = 0;
    foreach(ListItem myItem in CheckBoxList1.Items)
    {
    if(myItem.Selected == true)
    {
    num++;
    if(num > 2)
    {
    myItem.Selected =false;
    num--;
    }
    }
    }
    }