开发者

Checking multiple Radio buttons from different group boxes in c#

I am a newbie in C# I just have a doubt.I have two group boxes,each of them has three radio buttons in it,If I want to select each radio button from each groupbox and write a condition for that ,,How can I do that. Below is the code:

   public void SaveMyTextBoxContents()
        {

            string path = usbLetter +"MSREAD.txt";

            if (lbItems.SelectedIndex == -1)

            {

                        if (rdBtnMed.Checked)
                        {
                            using (StreamWriter File = new StreamWriter(filepath))
                            {
                                foreach (string item in lbItems.Items)
                                {
                                    saveAllText = medium + " " + item;
                                    outputFile.WriteLine(saveText);
                                }
                            }
                        }                        
}
                        else if (rdBtnMedium.Checked && rdBtnN.Checked)
                        {
                            using (StreamWriter File = new StreamWriter(filepath))
                            {
                   开发者_C百科             foreach (string item in lbItems.Items)
                                {
                                    saveAllText = mediumNo + " " + item;
                                    outputFile.WriteLine(saveText);
                                }
                            }
                        }



}
}  

Please help me I got stuck up with this.

Thanks Krik


Make small panels to the size of radio button pairs and place those radio buttons on them (two each). E.g separate for male, female; separate for young, old etc. The panel won't show on run. This will work Insha'Allah in a group box too.


You're brackets are off, so it only checks rdBtnMedium and rdBtnN if lblItems.SelectedIndex != 1. Here's what I think you need:

if (lbItems.SelectedIndex == -1)
{
    if (rdBtnMed.Checked)
    {
        using (StreamWriter File = new StreamWriter(filepath))
        {
            foreach (string item in lbItems.Items)
            {
                 saveAllText = medium + " " + item;
                 outputFile.WriteLine(saveText);
            }
        }
    }                        
    else if (rdBtnMedium.Checked && rdBtnN.Checked)
    {
        using (StreamWriter File = new StreamWriter(filepath))
        {
            foreach (string item in lbItems.Items)
            {
                saveAllText = mediumNo + " " + item;
                outputFile.WriteLine(saveText);
            }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜