private String id; private int row_number; //Fill first Combo private void fill_first_combo() { datagridview_col1.Items.Clear(); if (datagridview.SelectedRows.Count > 0) { string rcs = db_conn.connection(); using (var OraConn = new OracleConnection(rcs)) { using (var OraCmd = OraConn.CreateCommand()) { try { OraConn.Open(); OraCmd.BindByName = true; OraCmd.CommandText = "Oracle Command" OracleDataReader OraDataReader = OraCmd.ExecuteReader(); if (OraDataReader.Read() == false) { //MessageBox } else { using (var OraDat = new OracleDataAdapter(OraCmd)) { using (var table = new DataTable()) { OraDat.Fill(table); foreach (DataRow row in table.Rows) { foreach (DataColumn column in table.Columns) { if (row[column] != null) { if (column.ColumnName == "COLUMNNAME") { datagridview_col1.Items.Add(row[column.ColumnName].ToString()); id = row[column.ColumnName].ToString().Substring(0, 6); } } } } } } } } catch (OracleException ex) { //Exceptions } finally { OraConn.Dispose(); } } } } else { //MessageBox } } //Fill 2nd ComboBoxColumn private void fill_combobox2(int row_number) { datagridview_col2.Items.Clear(); string rcs = db_conn.connection(); using (var OraConn = new OracleConnection(rcs)) { using (var OraCmd = OraConn.CreateCommand()) { try { OraConn.Open(); OraCmd.BindByName = true; OraCmd.CommandText = "Oracle Command with id as a Parameter"; var id_param = new OracleParameter("id", id); OraCmd.Parameters.Add(id_param); OracleDataReader OraDataReader = OraCmd.ExecuteReader(); if (OraDataReader.Read() == false) { //MessageBox } else { using (var OraDat = new OracleDataAdapter(OraCmd)) { using (var combo2_table = new DataTable()) { OraDat.Fill(combo2_table); foreach (DataRow row in combo2_table.Rows) { foreach (DataColumn column in combo2_table.Columns) { if (row[column] != null) { if (column.ColumnName == "BUILDING_LESS") { datagridview_col2.Items.Add(row[column.ColumnName].ToString()); } } } } } } } } catch (OracleException ex) { //Catch Exceptions } finally { OraConn.Dispose(); } } } } //Trigger SelectionChange private void datagridview_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { ComboBox cb = e.Control as ComboBox; if (cb != null) { cb.SelectedIndexChanged -= new EventHandler(selectionchange); cb.SelectedIndexChanged += selectionchange; } } private void selectionchange(object sender, EventArgs e) { try { //ComboBox cb = (ComboBox)sender; String selected = (sender as ComboBox).SelectedItem.ToString(); if (datagridview.CurrentCell.ColumnIndex == 0) { row_number = datagridview.CurrentCell.RowIndex; id = selected.Substring(0, 6); if (!String.IsNullOrEmpty(id)) { fill_combobox2(row_number); } else if (String.IsNullOrEmpty(id)) { //MessageBox); } } else if (datagridview.CurrentCell.ColumnIndex == 1) { section = selected.Substring(0, 2); if (!String.IsNullOrEmpty(id) && !String.IsNullOrEmpty(value2)) { //MessageBox } else if (String.IsNullOrEmpty(id) && !String.IsNullOrEmpty(value2)) { //MessageBox } else if (String.IsNullOrEmpty(id) && String.IsNullOrEmpty(value2)) { //MessageBox } } } catch (Exception ex) { //MessageBox } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)