Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
how to use selected index change event in DataGridView combobox
Posted

You need to handle two events for the datagridview

EditingControlShowing of the datagridview and in the eventhandler attach the eventhandler for selectedindexchanged of the combobox

C#
this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(OnEditControlShowing);



C#
void OnEditControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control is ComboBox)
            {
                ((ComboBox)e.Control).SelectedIndexChanged += new EventHandler(OnSelectIndexChanged);
            }
        }
 
Share this answer
 
goooooooooooood but like this code
C#
if (e.Control is ComboBox)
               {
                   ((ComboBox)e.Control).SelectedIndexChanged += new System.EventHandler(this.onseleteddatagridomboboxevent);
               }




C#
private void onseleteddatagridomboboxevent(object sender, EventArgs e)
        {

                try
                {
                    string test = grd_setter.Rows[0].Cells["c2"].Value.ToString();
                         DataTable dt = pDAL.Get_Data("select  Date from tbl_packet where PNo='" + test.ToString() + "'");
                          d = dt.Rows[0][0].ToString();
                          grd_setter.Rows[0].Cells["c3"].Value = d.ToString();
                }
                catch { }
        }
 
Share this answer
 
Comments
Ravndra22 7-Feb-13 6:43am    
ZAHIDGAN:- Thts wht exactly I have done. bt still not working.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900