WindowsForms - If combobox.selecteditem is.... then....

IAKIL 1 Reputation point
2022-03-26T11:30:46.217+00:00

Hi, I need help with IF in my code and tried almost everything that I found on youtube tutorials but nothing worked.
I want to code that way, when I choose from comboBox1 item1 (1+x) and apply it it will type /example 60, when I choose from combobox item2 (5+y) it will type /example 300

Here is code
private void NEXT_Click(object sender, EventArgs e)
{

        {
            if (comboBox1.SelectedItem) is "1+x";
            t = " 60";
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
            SendKeys.Send("/timeout " + richTextBox1.Text + t);
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
            SendKeys.Send("{ENTER}");
        }

        {
            if (comboBox1.SelectedItem) = "5+y";
            t = " 300";
        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
        SendKeys.Send("/timeout " + richTextBox1.Text + t);
        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
        SendKeys.Send("{ENTER}");
        }

    }
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,968 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Petrus 【KIM】 546 Reputation points
    2022-03-28T00:57:52.563+00:00

    Syntax Error. Take a closer look at the code.

    if (comboBox1.SelectedItem) is "1+x";  
    
    ==> if (comboBox1.SelectedItem is "1+x") {    
             // insert your code here...
           }
    
    1 person found this answer helpful.
    0 comments No comments

  2. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2022-03-28T02:24:51.19+00:00

    Hi, @IAKIL

    Try to use equality operators: == instead of =.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.