3
Reply

How to bind ComboBox to a datagridview in a windows form

Renjith R

Renjith R

Feb 2 2015 5:16 AM
940
I Have to bind a comboBox to a datagridview in a windows form application. i have used the below code.
 DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.HeaderText = "Installation";
cmb.Name = "cmb";
cmb.MaxDropDownItems = 3;
cmb.Items.Add("--SELECT--");
cmb.Items.Add("Pre-Installation");
cmb.Items.Add("Installation");
cmb.Items.Add("Post-Installation");

By using the this code comboBox is binded in gridview, But it is displaying on the topside of the column, I need to display the comboBox to the center of the column and
--Select-- should display by default.
For displaying comboBox to center i have used this
 cmb.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

Thanks in advance

Answers (3)