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 .
- void populatecategorycombobox()
- {
- using (OleDbConnection Connection = new OleDbConnection(connectionString))
- {
- Connection.Open();
- OleDbDataAdapter sqlDa = new OleDbDataAdapter("SELECT * from category", Connection);
- DataTable dtbl = new DataTable();
- sqlDa.Fill(dtbl);
- cbxcategory.ValueMember = "catid";
- cbxcategory.DisplayMember = "catname";
- DataRow topItem = dtbl.NewRow();
- topItem[0] = 0;
- topItem[1] = "-Select-";
- dtbl.Rows.InsertAt(topItem, 0);
- cbxcategory.DataSource = dtbl;
- }
- }

Ahsan Raza43 reputationPosted Oct 9, 2019, 8:27 AM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Oct 9, 2019, 8:43 AM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Oct 9, 2019, 5:39 PM EDT
anna john33 reputationPosted Oct 9, 2019, 9:39 AM EDT
, thanks for the reply. the combo has values A,B,C from database. and also i added "Add new" value into combo. so when iclick on add new it should let me type in the value. i think i am not doing it right with your code, its not letting me type in values. can you please tell me how to handle that
anna john33 reputationPosted Oct 9, 2019, 10:50 AM EDT