Solved

ComboBox issues in .Net 2008 C# Windows Forms application

Posted on 2012-03-20
4
262 Views
Last Modified: 2012-03-20
I have a simple combobox that is populated using a dataset which gets data from a SQL server. This combobox (cmb1) is populated during the form's Load event

On the cmb1_SelectedIndexChanged event, I have another combobox (cmb2) populating based on the cmb1's value.

Problem is, whe the form loads, the second combo box is getting populated with the first element in cmb1. I need cmb2 to remain blank until the user selects something in cmb1.
0
Comment
Question by:CodeWrangler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37745091
Have you tried checking that something is selected:

protected void cmb1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (cmb1.SelectedIndex >= 0)
    {
        // Load cmd2
    }
}

Open in new window

0
 

Author Comment

by:CodeWrangler
ID: 37745107
Yep, thats is exactly what I am doing. As a temporary workaround, I am putting something in index 0 which I know will not return results from the database.
0
 

Author Comment

by:CodeWrangler
ID: 37745191
Figured it out. Thanks Kaufmed. Even though you suggested something I had already tried, it got me thinking on something I did incorrectly.
0
 

Author Comment

by:CodeWrangler
ID: 37745408
In case someone wanders in here for any combobox issues.. if you are wondering why the _SelectedIndexChanged event is firing when trying to populate comboxes using SQL.. use:

if (cmbKey2.SelectedIndex > -1 && cmbKey2.ContainsFocus == true)
            {....}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question