anna john

anna john

  • 1.8k
  • 33
  • 460

allow combobox to add user defined values at runtime

Oct 9 2019 11:23 AM
i have a combobox column[category] in my datagridview. the category column in datagridview shows values from a table. i want the combobox to add user defined values at run time and save it into database and show in combobox also.
 
i have the basic code to show data in the table to the combobox. can someone please guide me on how to accept user input and add it to database and combobox .
  1. void populatecategorycombobox()  
  2. {  
  3. using (OleDbConnection Connection = new OleDbConnection(connectionString))  
  4. {  
  5. Connection.Open();  
  6. OleDbDataAdapter sqlDa = new OleDbDataAdapter("SELECT * from category", Connection);  
  7. DataTable dtbl = new DataTable();  
  8. sqlDa.Fill(dtbl);  
  9. cbxcategory.ValueMember = "catid";  
  10. cbxcategory.DisplayMember = "catname";  
  11. DataRow topItem = dtbl.NewRow();  
  12. topItem[0] = 0;  
  13. topItem[1] = "-Select-";  
  14. dtbl.Rows.InsertAt(topItem, 0);  
  15. cbxcategory.DataSource = dtbl;  
  16. }  
  17. }  

Answers (5)