I have some code that checks a value in a combo box before it executes but it does not appear to be seeing the value selected in the combo box until I select the item in the combo box for a second time. Note the value in the combo box was set in a form and saved to a database. Now if I open that form again in pulls up the value previously set in the combo box from the database but it is as if it is not seen by the case statement unless I reselect the value.Im using a case statement when determining what to do based on the values in the combo box.

My code looks like this:

private void optypCB_Click(object sender, EventArgs e)
        {
            switch (optypCB.Text)
            {
                case "Draw":
                    wearTB.Text = "4";
                    pinsTB.Text = "0";
                    nitrogenLowerCheckBox.Checked = true;
                    densityTB.Text = Convert.ToString(.35); break;
                case "Trim":
                    wearTB.Text = Convert.ToString(4);
                    pinsTB.Text = Convert.ToString(4);
                    densityTB.Text = Convert.ToString(.35); break;
                case "Form":
                    wearTB.Text = Convert.ToString(4);
                    pinsTB.Text = Convert.ToString(4);
                    densityTB.Text = Convert.ToString(.35); break;
                case "Pierce":
                    wearTB.Text = Convert.ToString(4);
                    pinsTB.Text = Convert.ToString(4);
                    densityTB.Text = Convert.ToString(.35); break;
                case "Blank":
                    wearTB.Text = Convert.ToString(4);
                    pinsTB.Text = Convert.ToString(4);
                    densityTB.Text = Convert.ToString(.45); break;                    
                default:
                    throw new Exception("Unknown selection");
            }
        }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Im sorry but I don't understand what event should I use?

Why not find out what order they fire in, and when. take a text box, and a combo box, and assign an append line to the text box for each event in the combo box.

(you will need a multiline text box)

Liz im sorry but im not very experienced. I know how to create a multiline text box but how do I assing an append line for each event in the combo box? Thanks in advance.

have a try first..

I really have tried different things and searching the internet. But I can't figure out how to assign the events to a multiline text box.

I really have tried different things and searching the internet. But I can't figure out how to assign the events to a multiline text box.

Events for the Textbox control1:

void textBox1_LostFocus(object sender, System.EventArgs e)

{

listBox1.Items.Add("LostFocus event called of TextBox1");

}

void textBox1_GotFocus(object sender, System.EventArgs e)

{

listBox1.Items.Add("GotFocus event called of TextBox1");

}

void textBox1_Leave(object sender, System.EventArgs e)

{

listBox1.Items.Add("Leave event called of TextBox1");

}

void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)

{

listBox1.Items.Add("KeyUp event called of TextBox1");

}

void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

listBox1.Items.Add("KeyPress event called of TextBox1");

}

void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)

{

listBox1.Items.Add("KeyDown event called of TextBox1");

}

void textBox1_Enter(object sender, System.EventArgs e)

{

listBox1.Items.Add("Enter event called of TextBox1");

}

other than no code tags, using a listbox would work.
So, now you should see what events are triggered when, and know the reason for your first problem..

This article has been dead for over six months. Start a new discussion instead.