Home > DeveloperSection > Forums > How to get index value in combo box?
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    January-25-2014 1:18 AM

 C# C# 
Ratings:


 1 Reply(s)
 930  View(s)
Rate this:

I have a ComboBox with two values 'cash' and 'bank' if the user selects bank I need to enable two controls. I've tried below code:

private void comboBox_pay_type_SelectedIndexChanged(object sender, EventArgs e)

    {

        if (comboBox_bank.SelectedIndex == 1)

        {

            comboBox_bank.Enabled = true;

            textBox_recp_no.Enabled = true;

        }

    }

Problem is the index value is -1 for both cash and bank. Where have I made an error?



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-25-2014 1:44 AM

Hi Ankita,

You're just referencing the wrong combo box:

private void comboBox_pay_type_SelectedIndexChanged(object sender, EventArgs e)

{

    if (comboBox_pay.SelectedIndex == 1)

    {

        comboBox_bank.Enabled = true;

        textBox_recp_no.Enabled = true;

    }

}

You need to reference comboBox_pay here.


Don't want to miss updates? Please click the below button!

Follow MindStick