Cell Editing Techniques > Drop-down Controls > Detecting built-in combo box selections |
The ComboSelect event is fired when the user selects an item from the built-in combo box. This event is useful for determining the contents of the cell before the user exits edit mode.
Since the items displayed in the built-in combo box are often the only allowable values for the underlying data source, you may need to prevent your users from typing in the cell after making a selection. By setting the EditActive property to False within the ComboSelect event handler, you can force the grid to exit editing mode without allowing the user a chance to alter the selection (provided that the MarqueeStyle property is not set to 6 - Floating Editor).
Private Sub TDBGrid1_ComboSelect(ByVal ColIndex As Integer)
TDBGrid1.EditActive = False
End Sub
In this case, it is also a good idea to explicitly disallow keyboard input with the BeforeColEdit event:
Private Sub TDBGrid1_BeforeColEdit(ByVal ColIndex As Integer, _
ByVal KeyAscii As Integer, Cancel As Integer)
' Editing initiated via the keyboard.
If KeyAscii <> 0 Then
If TDBGrid1.Columns(ColIndex).Caption = "Columns" Then
Cancel = True
End If
End If
End Sub