private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (dataGridView1.CurrentCell.ColumnIndex == 2) { ComboBox comboBox = e.Control as ComboBox; if (comboBox != null) { comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelecteIndexChanged); } } } void comboBox_SelecteIndexChanged(object sender, EventArgs e) { try { DataSet ds = new DataSet(); string str = "select ProductCategory,ProductName from Product_Details where ProductID='" + dataGridView1.Rows[intRownum].Cells[2].Value + "'"; SqlConnection con = new SqlConnection(Class1.cs); con.Open(); SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds, "Product_Details"); if (ds.Tables["Product_Details"].Rows.Count > 0) { dataGridView1.Rows[intRownum].Cells[3].Value = ds.Tables["Product_Details"].Rows[intRownum][0].ToString(); dataGridView1.Rows[intRownum].Cells[4].Value = ds.Tables["Product_Details"].Rows[intRownum][1].ToString(); dataGridView1.Update(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)