Reputation: 275
I am using Visual Studio 2010, I created a data grid view, which has 2 columns. text column, the other is combo box Column.
private System.Windows.Forms.DataGridViewTextBoxColumn eqNameClmn;
private System.Windows.Forms.DataGridViewComboBoxColumn ClmnCabinetOptions;
this.eqNameClmn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.eqNameClmn.DataPropertyName = "Name";
this.eqNameClmn.HeaderText = "Cabinet/Mdf";
this.eqNameClmn.Name = "eqNameClmn";
this.eqNameClmn.ReadOnly = true;
//
// ClmnCabinetOptions
//
this.ClmnCabinetOptions.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ClmnCabinetOptions.DataPropertyName = "OptionValue";
this.ClmnCabinetOptions.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox;
this.ClmnCabinetOptions.HeaderText = "Display Options";
ClmnCabinetOptions.DataSource=
new object[] {
"Include Blocks and Cables",
"Include Blocks",
"None"};
this.ClmnCabinetOptions.Name = "ClmnCabinetOptions";
I have filled the combo box column with values that the user will have to choose from. To make my life easier, I created an object, in which I will use to bind to the data grid view, and retrieve whenever the user is finished.
public public class NeEquipmentDgvObj {
public NeEquipment NeEquipment;
public string Name { get; set; }
public bool IncludeBlocks;
public bool IncludeCables;
public string OptionValue { get; set; }
public NeEquipmentDgvObj(NeEquipment equipmentOb) {
Name = equipmentOb.EquipmentName;
NeEquipment = equipmentOb;
IncludeBlocks = false;
IncludeCables = false;
}
}
the property OptionValue will be used so when the combo box is set, this property gets set in the object and I can retrieve the data source of the data grid view after I am finished selecting values in the combo box per item in the list that is binded.
I am running into an issue that whenever the form is loaded, and the items are bounded, the combo box will not expand to show me the items within. if I preset the OptionValue, the combo box value will be set to that OptionValue but will not be changed and the combo box will not expand. What is causing this ?
Upvotes: 1
Views: 548
Reputation: 275
I got it solved, it turns out I had to change few properties. I set the EnableEditing to True on the DGV, and I set the read only property to false on the entire DGV as well.
Upvotes: 1