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 8496461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:51:43+00:00 2026-06-10T23:51:43+00:00

I have a datagrid with 2 combobox columns. I wrote selection changed event for

  • 0

I have a datagrid with 2 combobox columns. I wrote selection changed event for the combobox column as follows.

private void Grid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{ 
  ComboBox cb = e.Control as ComboBox;
                if (cb!=null)
                { cb.SelectionChangeCommitted -= new EventHandler(cb_SelectedIndexChanged);

                    // now attach the event handler
                    cb.SelectionChangeCommitted += new EventHandler(cb_SelectedIndexChanged);
                }
}

void cb_SelectedIndexChanged(object sender, EventArgs e)
     {
       var tb = datagrdADDTEMP.EditingControl as ComboBox;
       if (tb != null)
       str = tb.SelectedValue != null ? tb.SelectedValue.ToString() : null;
                     Assesment_Business_layer.Businesslayer bl = new Assesment_Business_layer.Businesslayer();
                     DataSet ds = new DataSet();**strong text**
                     ds = bl.GetSubCatNamesBA(str);
                     cmbDataGridSubCategory.DataSource = ds.Tables[0];
                     cmbDataGridSubCategory.DisplayMember = "SubCategoryName";
                     cmbDataGridSubCategory.ValueMember = "SubCategoryCode";
                 }
     }

its working well with the first combobox column but the problem is the above selection changed event is also raising when i am selecting the item from the second combobox column..but i dont want to raise the selection changed event for the second combos column. It should raise only for the first combobox only.

Please help as l’m stuck up with this problem.

  • 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-10T23:51:45+00:00Added an answer on June 10, 2026 at 11:51 pm

    The problem seems that you’re adding the event handler to any combo box, doesn’t matter what column it is, so you must find first in what column the event was triggered, for this you must take a look at the sender object of the Grid_EditingControlShowing event handler (which is a DataGridView) and its CurrentCell, SelectedColumns or SelectedCells properties.

    Example:

    private void Grid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if(((DataGridView)sender).CurrentCell.ColumnIndex == 0) //Assuming 0 is the index of the ComboBox Column you want to show
        {
            ComboBox cb = e.Control as ComboBox;
            if (cb!=null)
            {
                cb.SelectionChangeCommitted -= new EventHandler(cb_SelectedIndexChanged);
                // now attach the event handler
                cb.SelectionChangeCommitted += new EventHandler(cb_SelectedIndexChanged);
            }
        }
    }
    

    An example using SelectedColumns or SelectedCells, will be pretty much like this, if you want more info about that properties you can take a look at their documentation on MSDN

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

Sidebar

Related Questions

I have a datagrid with 2 columns. One column contains role information, the other
I have a DataGrid template column with ComboBox. When I select a value and
I have a wpf datagrid with 2 columns (ProductID and Description). ProductID column is
I have a datagrid in which i have combobox in a column. On a
i have combobox in datagrid (sourse in mysql (web)) how i can get value
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.
I have a WPF toolkit DataGrid as the dropdown in a ComboBox template. <toolkit:DataGrid
I have a datagrid in C#.net I have made some columns in grid editable.
I have a DataGrid with a CheckBox column. I show a popup if the
I have wpf datagrid with number of template columns. some of them have textbox

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.