0
votes

I have a class derived from DataSet that I'm using as a datasource. My DataGridView has 8 columns of which 3 are multiple value choices that are edited with drop down combo boxes.

  1. If I let the Datasource generate the columns for the DataGridView, then all of the column types are DataGridViewTextBoxColumn. However the DataGridView is populated with my original row values.

  2. If I set AutoGenerateColumns to false and add my own column types to the DataGridView I can add DataGridViewComboBoxColumn for the 3 columns that require it. However, the DataSource, while it contains the row data, does not populate the rows of my DataGridView.

Obviously I want both things to happen. The rows need to be populated from the DataSource and the column need to be correctly editable from the DataGridView as DataGridViewComboBoxColumns. Why can't I have both? What am I doing wrong.

Please note this is not a question about using a DataSource to populate the items in a ComboBox.

code fragment
            alarmDataSet = new AlarmDataSet(sAlarms);
            gridView.AutoGenerateColumns = false;
            gridView.DataSource = alarmDataSet;
            gridView.DataMember = sAlarms;

another code fragment
                    cm = new DataGridViewComboBoxColumn();
                    cm.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                    cm.HeaderText = ci.Name;
                    cm.Name = ci.DataName;
                    cm.MaxDropDownItems = 3;
                    cm.Items.Add("Once");
                    cm.Items.Add("Repeat");
                    cm.Items.Add("Off");
                    gridView.Columns.Add(cm);

Thanks

1
The DGV can and will add other than TextBox columns - images and checkboxes for example. However, combo columns need to be added manually mainly because each column will have its own DataSource to provide the choices in the drop down. You can let it generate the columns then modify it to add in the combosŇɏssa Pøngjǣrdenlarp
You are not setting the DataPropertyName of the DataGridViewComboBoxColumn - This should be set to the column in the source datatable to allow it to map to a value in drop downJayV

1 Answers

0
votes

if you set

DataGridView.AutoGenerateColumns = false 

Then You need to tell DataGeridView about which column of DataGridView bind to which column of DataSource (Property Name in case of list)

DataGridView.Column[0].DataPropertyName = "Column Name In Your DataSource That is bound to DataGridView Column 0"