2014-03-26 32 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