2014-03-26 34 views
0

我的問題是,我必須寫什麼代碼才能使radiobutton1顯示checkboxlist1不可見 - >Visible設置爲FalseRadiobutton必須勾選以顯示覆選框

只有當radiobutton1被選中時,我纔想顯示checkboxlist

我正在使用visual c#2012。希望你能幫助。

回答

2

您使用CheckedRadioButton的屬性來標識是否檢查了RadioButton。

從MSDN:RadioButton.Checked

獲取或設置指示該控制是否被選中的值。

試試這個:

if(radioButton1.Checked) 
{ 
    //Enable checkboxlist 
    CheckBoxList1.Visible=true; 
} 

編輯: 你應該處理它的RadioButton

的CheckedChanged事件處理程序試試這個:

private void radioButton1_CheckedChanged(object sender, EventArgs e) 
{ 
    if(radioButton1.Checked) 
    { 
     //Enable checkboxlist 
     CheckBoxList1.Visible=true; 
    } 
} 

編輯: 如果要禁止其他單選按鈕試試這個:

private void radioButton1_CheckedChanged(object sender, EventArgs e) 
{ 
    if(radioButton1.Checked) 
    { 
     //Enable checkboxlist 
     CheckBoxList1.Visible=true; 

     //Disable RadioButton 
     RadioButton2.Visible=false; 
    } 
} 
+0

好吧,我不喜歡你告訴我,但現在當我檢查的形式單選按鈕,在CheckBoxList的不出現。在那裏應該是空白區域... – user3083561

+0

@ user3083561:你應該在RadioButton檢查事件處理程序中處理它。檢查我編輯的答案。 –

+0

我可以再問一件嗎? 當我選擇一個單選按鈕和checkboxlist顯示我想禁用其他單選按鈕。那可能嗎 ? – user3083561