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

  • Home
  • SEARCH
  • 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 8786131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:32:19+00:00 2026-06-13T21:32:19+00:00

I am using Combobox SelectedIndexChanged event to perform few tasks. It is working nice.

  • 0

I am using Combobox SelectedIndexChanged event to perform few tasks. It is working nice. But when i am closing the form, SelectedIndexChanged gets fired and i get “Object reference not set to an instance of an object.” exception. My code is following-

    private void cmbProductName_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            Product p =(Product) cmbProductName.SelectedItem;

            RawItems = RawItem.GetEntityList(p.Id, ConnectionString);

        }
        catch (Exception ex)
        {
            CustomMessageBox.ShowSystemException(ex);
        }
    }

How to avoid the SelectedIndexChanged event being fired when form is closing?

Thanks
SKPaul.

  • 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-06-13T21:32:20+00:00Added an answer on June 13, 2026 at 9:32 pm

    If you want to perform the tasks only when user change selected item in combo box, it is better to implement the SelectionChangeCommitted event

    [EDIT]

    According to MSDN docs SelectionChangeCommitted occurs only when the ComboBox selection changes by user (via keyboard or mouse) and it is not raised when the selection changes programmatically.

    When a value is changed in the list, SelectionChangeCommitted event is fired first and then SelectedIndexChanged event is fired.

    So if we need to do anything on SelectedIndexChanged, we can remove it and do the same work in SelectionChangeCommitted event handler.

    Simply handle this event instead of SelectedIndexChanged as below:

    private void cmbProductName_SelectionChangeCommitted(object sender, EventArgs e)
    {
        /*
          Your event handling code
        */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on populating a combobox in visual studio 2005 using vb and I'm
I have been using the same Ajax Combobox everywhere in my project but as
I have two combobox in my form, using a mysql connection to a remote
I was using a combobox on my search form to select whether to consult
I'm using the combobox component and I want to manually dispatch the change event.
we can easily get index of combobox using FindString method int index = cboCountryTwoCode.FindString(localJob.DeliveryCountryTwoCode.Trim());
I'm working on building a List using Combobox that when a Client is selected
How to raise / handle the SelectionChanged event of WPF's ComboBox using the MVVM
I am trying to search through my DGV using a Combobox to get the
I am trying to bind the SelectionChanged event of ComboBox using RoutingCommand(same as we

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.