簡體   English   中英

TableLayoutPanel中的單獨單選按鈕組

[英]Separate radio button groups in TableLayoutPanel

我有一個TableLayoutControl,它用單選按鈕動態填充。 有四列。 我希望第1-3列中的單選按鈕在每一行中形成組,在第4列中的單選按鈕形成一個組。 換句話說,每行中的水平組和最后一列中的一個垂直組。 我怎樣才能做到這一點?

我認為,最好的方法是在表的每個單元格中放入一些分組控件(面板,groupBox,flowLayoutPanel等),並將單選按鈕添加到該組中。

假設您知道每個RadioButton哪一行和哪一列(例如,在創建一個名稱時rdb2_3表示它屬於TableLayoutControl第2行第3列),請向其中的所有對象添加CheckedChanged事件,例如:

    rdb.CheckedChanged += new EventHandler(rdb_CheckedChanged);

    void rdb_CheckedChanged(object sender, EventArgs e)
    {
        if (((RadioButton)sender).Checked)
            // Check if this RadioButton belong to column 4th so it belong to the column group
            if (((RadioButton)sender).Name.Substring(((RadioButton)sender).Name.Length - 1) == "4")
            {
                // Set Checked = false for all RadioButton in column 4 except this one
            }
            else
            {
                // Set Checked = false for all RadioButton in this RadioButton's row 4 except this one
            }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM