ComponentOne True DBGrid Pro 8
Using an arbitrary drop-down control

Normally, True DBGrid's default editing behavior is sufficient for most applications. In some cases, however, you may want to customize this behavior. One valuable technique is to use a drop-down list or combo box, or even another True DBGrid control, to allow selection from a list of possible values. This is easy to do with True DBGrid using virtually any Visual Basic or third-party control. The general approach follows, and a working example is given in Tutorial 9.

In general, displaying a drop-down list or combo instead of the standard True DBGrid editor involves the following steps:

1.   True DBGrid fires the BeforeColEdit event each time the user wants to edit a cell. To override the default editing process, cancel True DBGrid's default editor by setting the Cancel argument to True. Put code in BeforeColEdit to display the editing control you wish to show instead. Typically, you place the substitute editing control or drop-down on the same form as the grid, but make it invisible until you need it.

2.   When BeforeColEdit is triggered, there are five properties and one method you can use to determine the exact coordinates of the cell which is to be edited. The properties are Left (applies to grid and column), Top (grid and column), CellTop (column only, used with multiple line displays), Width (column only), and RowHeight (grid only). The method is RowTop (grid only). You can use these properties and method to position the custom editing control or drop-down relative to a grid cell. For example, you can place a ListBox control at the right edge of a cell and align its top border with that of the cell using the following code:

Dim Col As TrueDBGrid60.Column

Set Col = TDBGrid1.Columns(ColIndex)

 

With TDBGrid1

    List1.Left = .Left + Col.Left + Col.Width

    List1.Top = .Top + .RowTop(.Row)

End With

3.   You need to put code in the drop-down or combo which completes the editing process by assigning the selected value to the Text or Value property of the column being edited.

This method does not work, however, when the grid's MarqueeStyle property is set to the default value of 6 - Floating Editor. When the floating editor marquee is used, the BeforeColEdit event does not fire until the cell has been changed by the user. However, you can use the built-in column button feature to activate the drop-down as described in the next section.

For illustrations of other MarqueeStyle settings, see Highlighting the Current Row or Cell. An example of dropping down a Visual Basic ListBox control from a grid cell is given in Tutorial 9.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback