Reputation: 251
I have a dataGridview in a winform connected to a SQL table "something". The column in the grid are auto generated by the dataset. I have set one of the column to not visible because I need that particular column to be a combo box column which I have added by code:
DataGridViewComboBoxColumn comboCol1 = new DataGridViewComboBoxColumn();
comboCol1.Name = "foo1";
List<DateTime> periods = new List<DateTime>() { DateTime.Now.AddMonths(-1), DateTime.Now, DateTime.Now.AddMonths(1) };
List<string> colSource = periods.Select(x => x.ToString("MMM/yyyy")).ToList();
comboCol1.DataSource = colSource;
dataGridView1.Columns.Add(comboCol1);
dataGridView1.Columns["foo1"].DisplayIndex = 1;
This combobox column has items generated by the above code and I would like to post the selected value to the column "xx"in table"something". I can I achieve that?
Upvotes: 1
Views: 1078
Reputation: 3834
You can make use of DataPropertyName
of dataGridView to bind column like:
comboCol1.DataPropertyName = "foo1";
Upvotes: 1