I have a combobox in Datagridview (DataGridViewComboBoxColumn) , I want Some values to be selectable by the user and the others ( "Pending" value) Visible but not selectable.
this issue is that these data are in the database, and the pending value is not allowed to be selected by the user. Still, if I removed the value from the DataGridViewComboBoxColumn, I get unhandled exception error: the value datagridviewcomboboxcell is not valid.
Dim StudentClassStatus As New DataGridViewComboBoxColumn
StudentClassStatus.DataPropertyName = "StudentClassStatus"
StudentClassStatus.Name = "StudentClassStatus"
StudentClassStatus.HeaderText = "StudentClassStatus"
StudentClassStatus.Items.AddRange("Normal", "Absent", "Late", "Pending", "MakeUp")
StudentClassStatus.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox
Me.MyDataGrid.Columns.Add(StudentClassStatus)
Private Sub MyDataGrid_CellEnter(sender As Object, e As DataGridViewCellEventArgs) Handles MyDataGrid.CellEnter
Dim validClick As Boolean = (e.RowIndex <> -1 AndAlso e.ColumnIndex <> -1)
Dim datagridview = TryCast(sender, DataGridView)
If TypeOf datagridview.Columns(e.ColumnIndex) Is DataGridViewComboBoxColumn AndAlso validClick Then
datagridview.BeginEdit(True)
CType(datagridview.EditingControl, ComboBox).DroppedDown = True
End If
End Sub
Private Sub MyDataGrid_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles MyDataGrid.CurrentCellDirtyStateChanged
Me.MyDataGrid.CommitEdit(DataGridViewDataErrorContexts.Commit)
End Sub