用单选按钮验证

时间:2012-12-15 14:46:58

标签: c# radio-button panel tablelayoutpanel

我在面板中有10个RadioButton。

我在tableLayoutPanel中有10个面板,每个面板在不同的列中。

如何在列之间移动并验证每列中是否存在选定的radioButton?

谢谢。

1 个答案:

答案 0 :(得分:1)

我没有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;
    }
}

panelTableLayoutPanel

相关问题