Solved

ComboBox issues in .Net 2008 C# Windows Forms application

Posted on 2012-03-20
4
257 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
  • 3
4 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now