question

Booney-3048 avatar image
0 Votes"
Booney-3048 asked ·

C# if comobox1 is less then 2 combobox 2 say Fail

I have 2 combobox if CB1 is < 2 CB say Fail. This is what I have so far.

 private void cb_score_SelectedIndexChanged(object sender, EventArgs e)
         {
               
             if (cb_score.SelectedItem == "2")
             {
                 cb_pass_fail.Text = "Fail";
             }     
dotnet-csharpwindows-formsdotnet-sqlite
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
1 Vote"
DanielZhang-MSFT answered ·

Hi Booney-3048,
First convert the value of combobox1 to int type via Int32.TryParse method and then compare with 2.
Please refer to the following code:

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     int value;
     if (Int32.TryParse(comboBox1.Text, out value))
     {
    
         if (value < 2)
         {
    
             comboBox2.Text = "Fail";
         }
         else
         {
             comboBox2.Text = "";
         }
     }
     else 
     {
         comboBox2.Text = "";
     }
 }

Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.