I have 4 columns in datagrid.
sno Itemcode description uom in which itemcode is datagridcombobox
I want to fill datagrid other columns based on itemcode columncombobox selected value.
Am getting error in the below code and give me some idea to acheive this logic.
- protected void bindvalues()
- {
- OleDbConnection con = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=DESKTOP\SQLEXPRESS;User ID=sa; Password = aaa; Initial Catalog=bbb; Integrated secutity=SSPI");
- DataSet ds = new DataSet();
- con.Open();
- OleDbCommand cmd = new OleDbCommand(("Select itemcode from Item"), con);
- OleDbDataAdapter da = new OleDbDataAdapter();
- da.SelectCommand = cmd;
- DataTable dt = new DataTable();
- da.Fill(ds);
- dataGridView1.DataSource = ds;
- DataGridViewComboBoxColumn ic = new DataGridViewComboBoxColumn();
- ic.HeaderText = "ItemCode";
- ic.Name = "ItemCode";
- ic.MaxDropDownItems = 6;
- ic.DataSource = ds.Tables[0];
- ic.DisplayMember = "ItemCode";
- dataGridView1.Columns.Insert(1, ic);
- this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);
- con.Close();
- }
- private void editGridCellComboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (editGridCellComboBox.SelectedItem != null)
- {
- ComboBox cb = (ComboBox)sender;
- int result = ((ComboBox)sender).SelectedIndex;
- editGridCellComboBox.SelectedIndexChanged -= editGridCellComboBox_SelectedIndexChanged;
- if (cb.SelectedItem == null)
- return;
-
-
-
-
-
-
- OleDbConnection con = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=DESKTOP\SQLEXPRESS;User ID=sa; Password = aaa; Initial Catalog=bbb; Integrated secutity=SSPI");
- DataSet ds = new DataSet();
- OleDbCommand cmd1 = new OleDbCommand(("Select t2.description from Item t1 INNER JOIN ItemGroup t2 ON t1.Itemcode = '" + cb.SelectedItem.ToString() + "'"), con);
- OleDbDataAdapter da = new OleDbDataAdapter();
- da.SelectCommand = cmd1;
- da.Fill(ds);
- dataGridView1.Columns[2].DataPropertyName = "Itemdescription";
- editGridCellComboBox.SelectedIndexChanged += editGridCellComboBox_SelectedIndexChanged;
- }
- }
- ComboBox editGridCellComboBox = new ComboBox();
- private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
- {
- editGridCellComboBox = (ComboBox)e.Control;
- if ((editGridCellComboBox != null))
- {
- editGridCellComboBox.SelectedIndexChanged += editGridCellComboBox_SelectedIndexChanged;
- }
- }