简体   繁体   English

使用RadioButton进行验证

[英]validation with RadioButton

I have 10 RadioButton inside a panel. 我在面板内有10个RadioButton。

I have 10 panels inside a tableLayoutPanel, Each one in different column. 我在tableLayoutPanel中有10个面板,每个面板在不同的列中。

How can i move between the columns and validate that in each column there is a selected radioButton? 我如何在列之间移动并验证每列中是否有选定的radioButton?

Thank you. 谢谢。

I have no experiences with the TableLayoutPanel , but you could try this: 我没有使用TableLayoutPanel经验,但是您可以尝试以下方法:

bool allValid = true;
for(int c = 0; c < panel.ColumnCount; c++)
{
    var colRadios = panel.Controls.OfType<RadioButton>() 
        .Where(rb => panel.GetColumn(rb) == c);
    bool colValid = colRadios.Any(rb => rb.Checked);
    if(!colValid)
    {
        allValid = false;
        break;
    }
}

( panel is the TableLayoutPanel ) panelTableLayoutPanel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM