Normally, True DBGrid for WinForms' 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 for WinForms control, to allow selection from a list of possible values. This is easy to do with True DBGrid for WinForms using virtually any Visual Studio or third-party control. The general approach follows, and a working example is given in Tutorial 9: Attaching an Arbitrary Drop-Down Control to a Grid Cell.
In general, displaying a drop-down list or combo instead of the standard True DBGrid editor involves the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub C1TrueDBGrid1_BeforeColEdit(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.BeforeColEditEventArgs) Handles C1TrueDBGrid1.BeforeColEdit Dim r As Rectangle = Me.C1TrueDBGrid1.Splits(0).GetCellBounds(Me.C1TrueDBGrid1.Row, e.ColIndex) r = Me.C1TrueDBGrid1.RectangleToScreen(r) r = Me.RectangleToClient(r) Me.ListBox1.Left = r.Left Me.ListBox1.Top = r.Bottom End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void c1TrueDBGrid1_BeforeColEdit(object sender, C1.Win.C1TrueDBGrid.BeforeColEditEventArgs e) { Rectangle r = this.c1TrueDBGrid1.Splits[0].GetCellBounds(this.c1TrueDBGrid1.Row, e.ColIndex); r = this.c1TrueDBGrid1.RectangleToScreen(r); r = this.RectangleToClient(r); this.ListBox1.Left = r.Left; this.ListBox1.Top = r.Bottom; } |
This method does not work, however, when the grid's MarqueeStyle property is set to the value of MarqueeEnum.FloatingEditor. When the floating editor marquee is used, the BeforeColEdit event does not fire until the cell has been changed by the user. However, use the built-in column button feature to activate the drop-down box 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: Attaching an Arbitrary Drop-Down Control to a Grid Cell.