How can I prevent users from entering data in the DataGridViewComboBoxCells?

I have a project that uses several DataGridView controls. Most cells have a DataGridViewTextBoxCell conviction. I declare my controls like this:

Dim MyCell as DataGridViewCell

Later I will clarify whether they are DataGridViewTextBoxControls or DataGridViewComboBoxCells as follows:

MyCell = New DataGridViewTextBoxCell   ...or...
MyCell = New DataGridViewComboBoxCell

None of the places in my code require users to enter their own values ​​in Combo Boxes. That is, they are either hardcoded or the values ​​are collected from other data in the application.

Currently, users can highlight the list control as shown above and start typing whatever they like. For example, I have one combo box that offers the user a choice of integers from 1 to 9. I can select the combo box and enter "Hello, World!". if i wanted to.

What do you need to disable this ability? I am sure that there is property, but I still have to find it. I searched the Internet and found only the ability to add user-entered values ​​to the list and the flow of training instructions for data binding.

Thank you in advance! WITH

+3
source share
1 answer

Check here

EDIT

, , , ... , . (LOL ).

, comboxbox, comboboxcell, (Tired = Bad Engrish).

, , , , EditingControlShowing datagridview. dropdownstyle.

Private Sub datagridview_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)

    Dim c As ComboBox = e.Control

    If Not c Is Nothing Then

        c.DropDownStyle = ComboBoxStyle.DropDownList

    End If

End Sub
+3

Source: https://habr.com/ru/post/1781253/


All Articles