I have a quite some experience with DataGridViews, I cannot resolve this super simple issue...
I have a datagridview with a comboboxcolumn pre-set possible options (3 simple options). I have a database with table, form which I want to select the correct value for the cell in the column. I need to preserve the option for that the user might change the option later (and save it back to DB).
I created a datatable with options:
Dim dtShift As New DataTable
dtShift.Columns.Add("ValueM")
dtShift.Columns.Add("DisplayM")
dtShift.Rows.Add({123, "123"})
dtShift.Rows.Add({345, "345"})
dtShift.Rows.Add({678, "678"})
Then I assign the values this way (ds is dataset filled with data):
Me.DataGridView1.AutoGenerateColumns = False
Dim colpon As DataGridViewComboBoxColumn = Me.DataGridView1.Columns("PonLen")
With colpon
.DataSource = dtShift
.ValueMember = "ValueM"
.DisplayMember = "DisplayM"
.DataPropertyName = "PonLen".ToString ' contains an option like "345"
'.ValueMember = "PonLen" ' not needed, if Display member is saved
End With
...but this doesn't work well, even though it is as close as I could get. I The columns have correct options, there are correct values selected, but DataErrorEvent floods a test-log TextBox with errors like this:
Row=12 cell=3 : System.FormatException: DataGridViewComboBoxCell value is not valid.