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
Solved

ComboBox issues in .Net 2008 C# Windows Forms application

Posted on 2012-03-20
4
260 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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