user28314043
user28314043

Reputation: 1

How can I add items to DataGridViewComboBoxColumn

I have a a DataGridView which has a list assigned as a datasource and that list contains objects, in that list I have a List which contains objects and this object has a 'name' field. I created an unbound column with a type of DataGridViewComboBoxColumn. I want to add the name field mentioned before to the ComboBox.

I want to do something similar to that:

paymentTable.Rows[i].Cells[6].Items.Add(cn.name);

but this is not possible because, this way I'm going to get a DataGridViewCell type.

Upvotes: 0

Views: 35

Answers (1)

Musa AKYUZ
Musa AKYUZ

Reputation: 27

You have to specify the column type as a DataGridViewComboBoxColumn

var relatedColumn = (DataGridViewComboBoxColumn)paymentTable.Columns[0]; 
// 0 is your name column index

relatedColumn.Items.Add("New Item");

Upvotes: 0

Related Questions