c# - DropDown in datagridView -


hello have 2 datagridviews in windows form , have combobox in 1 datagridview somwthing enter image description here

when change value of combobox tables in datagridview should updated.for example if select second combobox outputmetadatafield1 columns of row should updated columns of 1st row in output metadata table.by not able add listener combobox dropdowns_selectedindexchanged.can tell m,e how that.

public partial class form1 : form {     public form1()     {         initializecomponent();         load_input_table();         load_output_table();     }     static string conn = @"data source=sumeet-pc\mssqlserver1;initial catalog=emids;integrated security=true";     sqlconnection connection = new sqlconnection(conn);      private void load_input_table()     {         string sql = "select * input_metadata";         sqldataadapter adapter = new sqldataadapter(sql, connection);         datatable table = new datatable();         adapter.fill(table);         bindingsource b = new bindingsource();         b.datasource = table;         datagridview1.datasource = b;         addcombo();      }     private void addcombo()     {         datagridviewcomboboxcolumn inputtablecombobox = new datagridviewcomboboxcolumn();         inputtablecombobox.headertext = "field";         inputtablecombobox.name = "inputtablecombobox";         string combosql = "select field input_metadata";         sqldataadapter comboadapter = new sqldataadapter(combosql, connection);         dataset ds = new dataset();         comboadapter.fill(ds);         inputtablecombobox.datasource = ds.tables[0];         inputtablecombobox.displaymember = "field";         inputtablecombobox.valuemember = "field";         datagridview1.columns.add(inputtablecombobox);     }     private void load_output_table()     {         string sql = "select * output_metadata";         sqldataadapter adapter = new sqldataadapter(sql, connection);         datatable table = new datatable();         adapter.fill(table);         bindingsource b = new bindingsource();         b.datasource = table;         datagridview2.datasource = b;     }     private void inputtablecombobox_selectedindexchanged(object sender, eventargs e)     {           messagebox.show("text");     } } 

thank you! found answer

public form1()     {         initializecomponent();         load_input_table();         load_output_table();         datagridview1.editingcontrolshowing += new datagridvieweditingcontrolshowingeventhandler(datagridview1_editingcontrolshowing);     }      static string conn = @"data source=sumeet-pc\mssqlserver1;initial catalog=emids;integrated security=true";     sqlconnection connection = new sqlconnection(conn);     datagridviewcomboboxcolumn inputtablecombobox = new datagridviewcomboboxcolumn();      private void load_input_table()     {         string sql = "select * input_metadata";         sqldataadapter adapter = new sqldataadapter(sql, connection);         datatable table = new datatable();         adapter.fill(table);         bindingsource b = new bindingsource();         b.datasource = table;         datagridview1.datasource = b;         addcombo();      }      private void addcombo()     {         inputtablecombobox.headertext = "field";         inputtablecombobox.name = "inputtablecombobox";         string combosql = "select field input_metadata";         sqldataadapter comboadapter = new sqldataadapter(combosql, connection);         dataset ds = new dataset();         comboadapter.fill(ds);         inputtablecombobox.datasource = ds.tables[0];         inputtablecombobox.displaymember = "field";         inputtablecombobox.valuemember = "field";         datagridview1.columns.add(inputtablecombobox);     }      private void load_output_table()     {         string sql = "select * output_metadata";         sqldataadapter adapter = new sqldataadapter(sql, connection);         datatable table = new datatable();         adapter.fill(table);         bindingsource b = new bindingsource();         b.datasource = table;         datagridview2.datasource = b;     }      private void datagridview1_editingcontrolshowing(object sender, datagridvieweditingcontrolshowingeventargs e)     {         combobox combo = e.control combobox;         if (combo != null)         {             combo.selectedindexchanged -= new eventhandler(inputtablecombobox_selectedindexchanged);             combo.selectedindexchanged += new eventhandler(inputtablecombobox_selectedindexchanged);         }     }     private void inputtablecombobox_selectedindexchanged(object sender, eventargs e)     {         messagebox.show(text);     } } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -