Hi all,
I'm trying to get a comboboxcell working in a datagridview. I DO NOT want a comboboxcolumn (that's what I have today) as the logic of my application states that only if the cell has a certain value when the form was opened, there should be a combobox instead of a regular textbox.
I've searched the net for a few hours and come up with the tiny piece of code below, but it doesn't work:
The "Dim combocell..." line gives the error: "Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewComboBoxCell'."
While I can understand the error message in itself and why it appears, this seems to be the manner in which other people have solved this problem. I'm puzzled!
Warm regards,
Pettrer
I'm trying to get a comboboxcell working in a datagridview. I DO NOT want a comboboxcolumn (that's what I have today) as the logic of my application states that only if the cell has a certain value when the form was opened, there should be a combobox instead of a regular textbox.
I've searched the net for a few hours and come up with the tiny piece of code below, but it doesn't work:
VB.NET:
For i As Integer = 0 To dgvM.Rows.Count - nr
If NullToStr(dgvM.Rows(i).Cells(COL_ANS).Value) = ans Then
Dim foljerstr As String = NullToStr(dgvM.Rows(i).Cells(COL_FOLJER).Value)
Dim combocell As DataGridViewComboBoxCell = dgvM.Rows(i).Cells(COL_FOLJER)
combocell.Items.Add("YES")
combocell.Items.Add("NO")
dgvM.Rows(i).Cells(COL_FOLJER).Value = foljerstr
End If
Next
The "Dim combocell..." line gives the error: "Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxCell' to type 'System.Windows.Forms.DataGridViewComboBoxCell'."
While I can understand the error message in itself and why it appears, this seems to be the manner in which other people have solved this problem. I'm puzzled!
Warm regards,
Pettrer