Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,
Posted
Updated 8-Jun-15 21:24pm
v2
Comments
Ralf Meier 9-Jun-15 3:44am    
Perhaps you add your code to your question so that we could see what you have done until now.
Basicly you could check inside your Button-script if the new entry for the Listbox is still existing.
kalaiselvan Indirajith 9-Jun-15 4:36am    
string fname="", lname="", faname="",mname="";
fname = textBox1.Text.ToString();
lname = textBox2.Text.ToString();
faname = textBox3.Text.ToString();
mname = textBox4.Text.ToString();

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);
}
else if(radioButton2.Checked)
{
value = radioButton2.Text;
listBox1.Items.Add(value);
}
string skil="";
if (checkBox1.Checked)
{
skil = checkBox1.Text;
listBox1.Items.Add(skil);
}
else if(checkBox2.Checked)
{
skil = checkBox2.Text;
listBox1.Items.Add(skil);
}
else if(checkBox3.Checked)
{
skil = textBox5.Text;
listBox1.Items.Add(skil);
}
}
the above style i have wrote..
If I anything did wrong please mention and guide me..

Thanks,
Ralf Meier 9-Jun-15 6:51am    
According to Solution 1 :
Did you really want that the Listbox only contents the last assign by the Button-press ?
kalaiselvan Indirajith 9-Jun-15 7:11am    
yes! Mr.Ralf

1 solution

C#
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);

}
}&lt;/pre&gt;</pre>
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900