BoS
BoS

Reputation: 9

WindowsForm Pressing tab key changes select data from combobox

I came across this program code and I would like use it multiple times on my Windows Form. I have tried it but it works only for comboBox1 and comboBox2 at the same time. If I disable code for let say comboBox1 then code works for comboBox2 and comboBox3. How can I rearrange the code that works for more then 5 combo boxes. Thanks.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {

        if (comboBox1.DroppedDown && keyData == Keys.Tab)
        {
           SendKeys.Send("{ENTER}");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);

        
        if (comboBox2.DroppedDown && keyData == Keys.Tab)
        {
            SendKeys.Send("{ENTER}");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);

        
        if (comboBox3.DroppedDown && keyData == Keys.Tab)
        {
            SendKeys.Send("{ENTER}");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Upvotes: 0

Views: 68

Answers (1)

BoS
BoS

Reputation: 9

I found solution.

        if (comboBox1.DroppedDown)
        {
            if (comboBox1.DroppedDown && keyData == Keys.Tab)
            {
                SendKeys.Send("{ENTER}");
                return true;
            }
        }


        else if (comboBox2.DroppedDown)
        {
            if (comboBox2.DroppedDown && keyData == Keys.Tab)
            {
                SendKeys.Send("{ENTER}");
                return true;
            }
        }


        else if (comboBox3.DroppedDown)
        {
            if (comboBox3.DroppedDown && keyData == Keys.Tab)
            {
                SendKeys.Send("{ENTER}");
                return true;
            }
        }


        return base.ProcessCmdKey(ref msg, keyData);

}

Upvotes: 0

Related Questions