本文介绍了获得结果后如何清除所有值(文本框,复选框,列表框等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是初学者级别的C#。我为我的小项目编写了代码。在一个表单中我创建了文本框,复选框,列表框,单选按钮就像一个应用程序。提交按钮后,结果显示在列表框中。如果我双击结果将进入我的列表框双重输入......并且持续..你能不能指导我如何清除价值...
谢谢,
Hi All,
I am beginner level of C#. I have wrote coding for my small project. In a form i have created text box,check box,list box,radio button its like an application. After submitting button result has shown in list box. If I double click result will come in my list box double entry... and continuously.. can you plz guide me how can i clear values...
Thanks,
推荐答案
string fname="", lname="", faname="",mname="";
fname = textBox1.Text.ToString();
lname = textBox2.Text.ToString();
faname = textBox3.Text.ToString();
mname = textBox4.Text.ToString();
//you ll not find double entry in your list box
ListBox1.Items.Clear();
//no need not to write tostring() to a string fname,lname or mname
listBox1.Items.Add(fname.ToString() + lname.ToString());
listBox1.Items.Add(faname.ToString());
listBox1.Items.Add(mname.ToString());
string value="";
if(radioButton1.Checked)
{
//value = radioButton1.Text;
//listBox1.Items.Add(value);
listBox1.Items.Add(radioButton1.Text);
}
else if(radioButton2.Checked)
{
//value = radioButton2.Text;
listBox1.Items.Add(radioButton2.Text);
}
string skil="";
if (checkBox1.Checked)
{
//skil = checkBox1.Text;
listBox1.Items.Add(checkBox1.Text);
}
else if(checkBox2.Checked)
{
//skil = checkBox2.Text;
listBox1.Items.Add(checkBox2.Text);
}
else if(checkBox3.Checked)
{
//skil = textBox5.Text;
listBox1.Items.Add(textBox5.Text);
}
}</pre></pre>
这篇关于获得结果后如何清除所有值(文本框,复选框,列表框等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!