我是C#的新手我只是有疑问。我有两个组合框,每组有三个单选按钮,如果我想从每个组合框中选择每个单选按钮并为其写一个条件,我怎样才能做到这一点。以下是代码:
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))
{
foreach (string item in lbItems.Items)
{
saveAllText = mediumNo + " " + item;
outputFile.WriteLine(saveText);
}
}
}
}
}
请帮助我,我对此感到困惑。
谢谢Krik
答案 0 :(得分:2)
将小面板制作成单选按钮对的大小,并将这些单选按钮放在它们上面(每个两个)。例如男性,女性;分别为年轻人,老年人等。小组将不会在运行中显示。这也将在集体框中运作Insha'Allah。
答案 1 :(得分:0)
你的括号是关闭的,所以它只检查rdBtnMedium和rdBtnN,如果lblItems.SelectedIndex!= 1.这是我认为你需要的:
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);
}
}
}
}