Reputation: 651
I am adding DataGridViewComboBoxCell
to datagridview
column and want to set the first item as selectedItem / selectedIndex
, but there are some examples to achieve this if only datasource
is assigned to it, but I don't want to use datasource
Here is my code
Dim col As New DataGridViewComboBoxCell
For Each r As DataRow In myDataTable.Rows
col.Items.Add(r("Months"))
Next
Dim row As New DataGridViewRow
row.CreateCells(dgv)
row.Cells(0) = col
dgv.Rows.Add(row)
Thanks
Upvotes: 1
Views: 474
Reputation: 5454
When dealing with altered DataGridView columns, you want to work with the Value property. Add this line of code somewhere before row.Cells(0) = col
:
col.Value = col.Items(0)
Upvotes: 3