Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to add some values in DataGridView ComboBox column, but

for example- 1st row the data will "abcd" in ComboBox Column
2nd row the data will be "abcdefg" in ComboBox Column

means I want different items in different rows on same ComboBox Column.
Posted
v2

Simply add new comboBox Cell in every row
C#
DataGridViewComboBoxCell dgvCmbCell;
dgvCmbCell = (DataGridViewComboBoxCell)myGrid.Rows[rowInx].Cells[colInx];
dgvCmbCell.Items.Clear();
dgvCmbCell.Value = null;
//And make your loop 
while (...)
{
    dgvCmbCell.Items.Add(.....);
}

I believe it will reach your requirement;
 
Share this answer
 
v3
how about add first the row then update the items in the ComboBoxColumn
VB
Dim dtgCol As DataGridViewComboBoxCell
Dim row As String()

row = New String() {"0", "1"}
dtgView.Rows.Add(row)

dtgCol = dtgView.Rows(0).Cells(2)
dtgCol.Items.Add("comboitem1")
dtgCol.Items.Add("comboitem2")

row = New String() {"2", "3"}
dtgView.Rows.Add(row)

dtgCol = dtgView.Rows(0).Cells(2)
dtgCol.Items.Add("comboitem1")
dtgCol.Items.Add("comboitem2")
dtgCol.Items.Add("comboitem3")


this is just my idea.. I already done this... hope this helps
 
Share this answer
 
Comments
Omkaara 4-Oct-13 7:07am    
No row can be added to a DataGridView control that does not have columns. Columns must be added first.

Its Showing above error
hansoctantan 4-Oct-13 7:27am    
what do you mean?
hansoctantan 4-Oct-13 7:31am    
I don't know if this will answer your question...

Dim cmbCol As New DataGridViewComboBoxColumn()
cmbCol.HeaderText = "ColName"
dtgView.Columns.Add(cmbCol)

That will add column combobox in grid

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