Bineesh  Viswanath

Bineesh Viswanath

  • NA
  • 1k
  • 771.7k

Fill ComboBox only when other comboBox is filled in ADO.NET

Nov 14 2013 12:43 AM
Sir, I need your help.

I have three comboBoxes  - cmbCountry, cmbState and cmbDistrict.

I called cmbCountry filling in Form_Load  and sets its Index to zero.

I called cmbState comboBox fill in SelectedValueChanged event of cmbCountry. Its index sets to -1.

The core area of my problem is from here.

Currently, cmbDistrict comboBox  is invisible. Only when I select a state,  I want to fill  and visible the cmbDistrict .

Here my code:-

private void cmbCountry_SelectedValueChanged(object sender, EventArgs e)
        {
            try
            {
               if (cmbCountry.SelectedIndex > -1 && cmbCountry.SelectedValue.ToString() != "System.Data.DataRowView")
                {
                    StateComboFill();
                  
                }
              
            }

            catch (Exception)
            {
               throw;
            }


        }
        private void cmbState_SelectedValueChanged(object sender, EventArgs e)
        {
            try
            {
                 if (cmbState.SelectedIndex>-1 && cmbState.Text != "System.Data.DataRowView")
                    {

                        lblDistrict.Visible = true;
                        cmbDistrict.Visible = true;
                        FillDistrict();
                    }

            }

            catch (Exception)
            {

                throw;
            }
        }
  private void cmbDistrict._SelectedValueChanged(object sender, EventArgs e)
        {
            try
            {
               
                        if (cmbDistrict..SelectedValue.ToString() != null && cmbDistrict..SelectedValue.ToString() != "System.Data.DataRowView" &&cmbDistrict.SelectedIndex != -1)
                        {

                            FillGridCorrespondingToDistrict();
   
                        }
                    }
                }
            }

            catch (Exception)
            {
               throw;
            }

        }

 my current prblem is when i select a country,  cmbDistrict combo is visible and data filled into it.

Answers (5)