본문 바로가기
C#.Net

c# CroupBox 내 선택 된 RadioButton Text 찾기 및 선택

by 호야호잇 2024. 11. 20.

Text 찾기

 //
        private string selected_RadioButton_String(GroupBox control)
        {
            foreach (Control groupBox in control.Controls)
            {
                if (groupBox.GetType() == typeof(RadioButton))
                {
                    RadioButton rb = groupBox as RadioButton;
                    if (rb.Checked && rb != null)
                    {                       
                        return rb.Text;
                        
                    }
                }
            }
            return "";
        }

 

Text 선택

 //
        private void select_RadioButton_String(GroupBox control, string selComTxt)
        {
            foreach (Control groupBox in control.Controls)
            {
                if (groupBox.GetType() == typeof(RadioButton))
                {
                    RadioButton rb = groupBox as RadioButton;
                    if (rb.Text == selComTxt)
                    {
                        rb.Checked = true;
                    }
                }
            }
           
        }