Israel

Israel

  • 693
  • 1.3k
  • 219.4k

Do not allow twice values into a textbox

Aug 28 2015 8:52 PM
Hi!
 
I have one combobox with a textbox.
Inside of my combobox I have three items (Morning, afternoon, goodnight). Then each selection is displayed into the textBox.
What I need to do?
When I select "morning" for example I would like that even I selected the second way its not should appear twice into the textbox (only once). Its allow to  appear again ONLY when the textbox its clean it.
 
My code:
 
private void cbxChoice_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cbxChoice.SelectedIndex)
{
case 0:
//Morning
textDisplay.Text += "\n" + Environment.NewLine + cbxChoice.Text + Environment.NewLine + ",";
textDisplay.clear();
break;
 
case 1:
//Afternoon
textDisplay.Text += "\n" + Environment.NewLine + cbxChoice.Text + Environment.NewLine + ",";
textDisplay.clear();
break;
 
case 2:
//Night
textDisplay.Text += "\n" + Environment.NewLine + cbxChoice.Text + Environment.NewLine + ",";
textDisplay.clear();
break;
 

Answers (12)