# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

.topic ctrl.dbgrid
.title DBGrid
.toc 1 DBGrid
.index DBGrid
.index Data-Bound Grid

.h1 DBGrid

VB Equivalent: DBGrid -- DVX Widget: dbgrid | Name Prefix: DBGrid

A data-bound grid that displays records from a Data control in a tabular format. Columns auto-populate from the query results. Bind the grid using the DataSource property. Click a column header to sort; drag a column border to resize. Selecting a row moves the bound Data control's cursor to that row.

.h2 Type-Specific Properties

.table
  Property     Type      Description
  ----------   -------   -------------------------------------------
  DataSource   String    Name of the Data control that supplies records.
  GridLines    Boolean   Show or hide grid lines between cells (default: True).
.endtable

.h2 Type-Specific Methods

.table
  Method    Parameters   Description
  -------   ----------   -------------------------------------------
  Refresh   (none)       Reload and redraw the grid from the Data control.
.endtable

.h2 Type-Specific Events

.table
  Event      Parameters   Description
  --------   ----------   -------------------------------------------
  Click      (none)       Fires when a row is clicked.
  DblClick   (none)       Fires when a row is double-clicked. Default event.
.endtable

Default Event: DblClick

.h2 Example

.code
Begin Data Data1
    DatabaseName = "books.db"
    RecordSource = "titles"
End

Begin DBGrid DBGrid1
    DataSource = "Data1"
    GridLines  = True
End

Sub Form_Load ()
    Data1.Refresh
End Sub

Sub DBGrid1_DblClick ()
    MsgBox "Opening row " & Str$(Data1.BOF)
End Sub
.endcode

.link ctrl.common.props Common Properties, Events, and Methods
.link ctrl.data Data
.link ctrl.databinding Data Binding
