Click here to Skip to main content
13,143,985 members (34,348 online)
Rate this:
 
Please Sign up or sign in to vote.
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 18-Jan-11 1:22am
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

use this link

http://homepage.ntlworld.com/herring1/datagrid.html
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

> 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);
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 1 Nov 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100