Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How can we raise ComboBox Drop down event on a button’s click event in .net 2.0.

Author: DevAsp Team
Download Source Code : 687_AutocomboboxDrop.zip

In this simple article you will learn how we raise ComboBox Drop down event on a button’s click event.

Simply just create New Project of C#.

 

Now drag one Button, eight ComboBoxes on the form

 

 

Now just write code on Form Load Event

 

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DevAsp ComboBox Controller";

           

            this.button1.Text = "Drop All";

 

            this.comboBox1.Items.Clear();

 

            this.comboBox2.Items.Clear();

 

            this.comboBox3.Items.Clear();

 

            this.comboBox4.Items.Clear();

 

            this.comboBox5.Items.Clear();

 

            this.comboBox6.Items.Clear();

 

            this.comboBox7.Items.Clear();

 

            this.comboBox8.Items.Clear();

 

            this.comboBox1.Items.Add("www.DevAsp.com");

            this.comboBox1.Items.Add("www.DevAsp.net");

 

 

            this.comboBox2.Items.Add("www.DevAsp.com");

            this.comboBox2.Items.Add("www.DevAsp.net");

           

 

            this.comboBox3.Items.Add("www.DevAsp.com");

            this.comboBox3.Items.Add("www.DevAsp.net");

           

 

            this.comboBox4.Items.Add("www.DevAsp.com");

            this.comboBox4.Items.Add("www.DevAsp.net");

           

 

            this.comboBox5.Items.Add("www.DevAsp.com");

            this.comboBox5.Items.Add("www.DevAsp.net");

           

 

            this.comboBox6.Items.Add("www.DevAsp.com");

            this.comboBox6.Items.Add("www.DevAsp.net");

           

 

            this.comboBox7.Items.Add("www.DevAsp.com");

            this.comboBox7.Items.Add("www.DevAsp.net");

           

 

            this.comboBox8.Items.Add("www.DevAsp.com");

            this.comboBox8.Items.Add("www.DevAsp.net");

           

           

        }

 

 

Write code on Button Click Event

 

private void button1_Click(object sender, EventArgs e)

        {

           

            comboBox1.DroppedDown = true;

            this.comboBox1.SelectedIndex = 0;

 

            comboBox2.DroppedDown = true;

            this.comboBox2.SelectedIndex = 0;

 

            comboBox3.DroppedDown = true;

            this.comboBox3.SelectedIndex = 0;

 

            comboBox4.DroppedDown = true;

            this.comboBox4.SelectedIndex = 0;

 

            comboBox5.DroppedDown = true;

            this.comboBox5.SelectedIndex = 0;

 

            comboBox6.DroppedDown = true;

            this.comboBox6.SelectedIndex = 0;

 

            comboBox7.DroppedDown = true;

            this.comboBox7.SelectedIndex = 0;

 

            comboBox8.DroppedDown = true;

            this.comboBox8.SelectedIndex = 0;

        }

 

Now here you can write any code in dropdown event of combobox

 

private void comboBox1_DropDown(object sender, EventArgs e)

        {

            this.comboBox1.SelectedIndex = 1;

        }

 

        private void comboBox2_DropDown(object sender, EventArgs e)

        {

            this.comboBox2.SelectedIndex = 1;

        }

 

        private void comboBox3_DropDown(object sender, EventArgs e)

        {

            this.comboBox3.SelectedIndex = 1;

 

        }

 

        private void comboBox4_DropDown(object sender, EventArgs e)

        {

            this.comboBox4.SelectedIndex = 1;

 

        }

 

        private void comboBox5_DropDown(object sender, EventArgs e)

        {

            this.comboBox5.SelectedIndex = 1;

 

        }

 

        private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)

        {

            this.comboBox6.SelectedIndex = 1;

 

        }

 

        private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)

        {

            this.comboBox7.SelectedIndex = 1;

 

        }

 

        private void comboBox8_SelectedIndexChanged(object sender, EventArgs e)

        {

            this.comboBox8.SelectedIndex = 1;

 

        }

 

This is very simple way to control Combox with some other control.

 

Article Comments
The dropdown event is not available for combobox if we were using VS 2008 with .NET 3.5 Framework for Windows mobile 6.1 plattform .

Is there a way to identify it ?

Posted on 1/23/2010 1:47:40 PM by João Nelson

private const uint CB_SHOWDROPDOWN = 0x014f;
[DllImport("Coredll.dll", EntryPoint = "SendMessage", SetLastError = true)]
private static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

void myfunc(ComboBox comboBox)
{
SendMessage(comboBox.Handle, CB_SHOWDROPDOWN, 1/*TRUE*/, 0);
}

Posted on 2/26/2010 4:38:52 AM by artcoding

private void comboBox1_Click(object sender, EventArgs e)
{
comboBox1.DroppedDown = true;
}

private void comboBox1_DropDown(object sender, EventArgs e)
{
comboBox1.Items.Clear();
comboBox1.Items.Add("1");
comboBox1.Items.Add("2");
comboBox1.Items.Add("3");
comboBox1.Items.Add("4");
}

Posted on 6/21/2010 12:13:34 PM by sumit

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get all SQL Severs on the Local Area network using SQL Server Management Object in .net 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net