Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I have a small requirement. I need to change the text column of a datagridview to combobox column at edit time.How to achieve this?. What i have done so far is given below. the problem i am facing is that. when the edit mode begins a new column is generated and all the rows of the specified column has changed to combobox type.
My datagridview is bounded to a datasource.
Any idea or help is appreciated
C#
 private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
else if (colIndex == 6)
            {
                DataTable comboSource = new DataTable("comboSource");
                comboSource.Columns.AddRange(new DataColumn[] {
                new DataColumn("id"),
                new DataColumn("stat") });
                comboSource.Rows.Add(1, "");
                comboSource.Rows.Add(2, "Left");
                comboSource.Rows.Add(3, "Expire");             


                DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
                col.DataPropertyName = "stat";
                col.DataSource = comboSource;
                col.DisplayMember = "stat";
                col.ValueMember = "id";
                dataGridView1.Columns.Add(col);
            }
}
Posted
Comments
Sergey Alexandrovich Kryukov 28-Dec-14 12:37pm    
Please explain what do you mean by "edit time". Why doing so, what do you want to achieve?
—SA
jinesh sam 29-Dec-14 3:45am    
@sergey "Edit time" means suppose when the user begins to change some value of the cell.In the intial stage it is like a text column. when the user enter into the cell the cell type has to change like dropdownlist so as to select the item from the list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900