• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

ComboBox issues in .Net 2008 C# Windows Forms application

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
CodeWrangler
Asked:
CodeWrangler
  • 3
1 Solution
 
käµfm³d 👽Commented:
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
 
CodeWranglerAuthor Commented:
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
 
CodeWranglerAuthor Commented:
Figured it out. Thanks Kaufmed. Even though you suggested something I had already tried, it got me thinking on something I did incorrectly.
0
 
CodeWranglerAuthor Commented:
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now