Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:29:17+00:00 2026-05-24T20:29:17+00:00

When i load a form that contains a combobox, i noticed that the comboBox_SelectedIndexChanged

  • 0

When i load a form that contains a combobox, i noticed that the comboBox_SelectedIndexChanged event is triggered, but i don’t want to use that event at form load, what do you propose to avoid this problem.

I tried to stop it by setting a Boolean to false, and told to the comboBox_SelectedIndexChanged to execute only if the boolean equals true. of course after the form_load event finishes, I set the boolean to true, but that’s not working.

Any help would be appreciated

here is the code :

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
                {
                    setprice(comboBox1, textBox1, textBox2, 0);


                }

 public void setprice(ComboBox combo, TextBox prix, TextBox qt, int num)
            {
                if (flag1[num] == 1)
                {
                    SqlDataReader reader = null;
                    try
                    {
                        SqlCommand command = mySqlConnection1.CreateCommand();
                        command.CommandText = "select prix_vente_ttc, prix_vente_ht from STK_PRODUITS_GENERIQUE where num_produit=" + combo.SelectedValue.ToString();
                        reader = command.ExecuteReader();
                        while (reader.Read())
                        {

                            prix_ttc[num] = Convert.ToDouble(reader.GetDecimal(0));
                            prix_ht[num] = Convert.ToDouble(reader.GetDecimal(1));
                            prix_htt[num] = prix_ht[num] * Convert.ToInt16(qt.Text);
                            //fact.forfait.setPrix_ht( prix_htt);
                            //fact.forfait.setTva(prix_ttct - prix_htt);

                            prix_ttct[num] = prix_ttc[num] * Convert.ToDouble(qt.Text);
                            prix.Text = Convert.ToString(prix_ttct[num]);
                        }
                        //textBox3_TextChanged(null, null);
                        // reader.Close();


                    }
                    catch (Exception excep)
                    {
                        MessageBox.Show(excep.Message); 
                        //if (reader != null) reader.Close();
                    }
                    if (reader != null) reader.Close();


                }
                flag1[num] = 1;
            }

private void vidangeform_Load(object sender, EventArgs e)
        {
            flag1[0] = 0;
            flag1[1] = 0;
            SqlDataReader reader = null;
            try
            {
                nextform = new filtreform();


                SqlCommand command = mySqlConnection1.CreateCommand();
                command.CommandText = "select designation, num_produit  from STK_PRODUITS_GENERIQUE where STK_PRODUITS_GENERIQUE.num_famille in (select num_famille from parametrage_vidange where parametrage_vidange.produit='forfait_vidange')";

                Dictionary<int, string> dict = new Dictionary<int, String>();
                reader = command.ExecuteReader();

                while (reader.Read())
                {

                    dict.Add(reader.GetInt32(1), reader.GetString(0));

                }
                comboBox1.DataSource = new BindingSource(dict, null);
                comboBox1.DisplayMember = "Value";
                comboBox1.ValueMember = "Key";
                reader.Close();

                command = mySqlConnection1.CreateCommand();
                command.CommandText = "select designation, num_produit  from STK_PRODUITS_GENERIQUE where STK_PRODUITS_GENERIQUE.num_famille in (select num_famille from parametrage_vidange where parametrage_vidange.produit='huile')";

                dict = new Dictionary<int, String>();
                reader = command.ExecuteReader();

                while (reader.Read())
                {

                    dict.Add(reader.GetInt32(1), reader.GetString(0));

                }
                comboBox2.DataSource = new BindingSource(dict, null);
                comboBox2.DisplayMember = "Value";
                comboBox2.ValueMember = "Key";
                reader.Close();
            }
            catch (Exception ep) { MessageBox.Show("problème de connexion avec le serveur ou resultat retourné nul. \n" + ep.Message); if(reader != null) reader.Close(); }



        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:29:18+00:00Added an answer on May 24, 2026 at 8:29 pm

    SelectedIndexChanged is fired when you set the DataSource for the comboBox.

    It is hard to come up with a clean way of managing events with WinForms, but what you could do is instead of subscribing to the event at design-time, you could subscribe to it after you set the dataSource:

    • remove the event handler comboBox1_SelectedIndexChanged from your combobox events in design time
    • add the following line at the end of your vidangeform_Load method:

      comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a child form that is throwing an ApplicationException in the Load event
I am trying this in my Form Load Event cmdCancel.Attributes.Add(onClick, document.forms[0].reset();return false;) but it
I have a form that contains a Shockwave Flash object. I want that after
I have a Windows Form that takes quite a bit of time to load
I'm trying to load a page that is basically an edit form inside a
We are using jquery to .load() a form into a div We then use
Short version: I want to trigger the Form_Load() event without making the form visible.
When i add a listview to my form and in form load event i
I want to run a console application (eg app.exe) from a windows form load
In the project I'm working on, there is a certain form that contains an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.