Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I add items to an already existing combobox cell in a datagridview combobox column ,
Each row contains a different items in the combobox column ,
I want to add the items to the specific combobox cell of a specific row ,
I tried something like this but it didn't work :

dataGridView1.Rows[0].Cells[2].Items.Add();


Thank you .
Posted
Updated 1-Nov-16 2:08am
v4
Comments
Pavan Kumar 10-Sep-14 7:27am    
Hi i got same problem now if you are solved the problem please tell me the solution
thanks in advance

DataGridViewComboBoxColumn colType = new DataGridViewComboBoxColumn(); 
colType.HeaderText = "Type"; 
colType.DropDownWidth = 90; 
colType.Width = 90; 
colType.MaxDropDownItems = 5; 
this.dataGridView1.Columns.Insert(7, colType); 
colType.Items.AddRange("A", "N", "P", "S", "Z"); 
this.dataGridView1.Columns[7].DataPropertyName = "trans_type";



this can help may be
 
Share this answer
 
Comments
Michael Waguih 18-Jan-11 7:41am    
Sorry I need a code for an already existing column
each row combobox cell contains different items
Thanks
use this link

http://homepage.ntlworld.com/herring1/datagrid.html
 
Share this answer
 
Comments
Michael Waguih 20-Jan-11 3:36am    
This link help me to create a new column with the same items in all cells of this column .
but I need a way to add items in specific cell of a specific row ,
Thanks
I need a way to add items in specific cell of a specific row in the combobox column of a datagridview ,
Can anyone help me.
 
Share this answer
 
v2
C#
> dataGridView1.Rows[0].Cells[2].Items.Add();

First, you do not say where this code appears; the most likely problem is that it is in the form constructor, which is too early, so put it in the Form Load or the DataBindingComplete event handler.

Second, it is advisable to clear the Items collection first because if you don't and the DataGridViewComboBoxColumn has anything in its items list it will be present, and if you run the above line more than once the items will accumulate. This code works for me:
DataGridViewComboBoxCell comboCell = (DataGridViewComboBoxCell)dataGridView1[2,0];
comboCell.Items.Clear();
comboCell.Items.AddRange(arrayOfItemsForRow0);
 
Share this answer
 

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