McBasic™Get McBasic™ ↗
Build 881
Controls · Visual control
DataGrid component icon

DataGrid

Combine provider paging with a local filter and a parameterized database search.

50 properties29 events1 methodsDefault: SelectionChanged

Use it in a Form#

FilterText operates on loaded rows. A database search changes the SQL query and may match rows that are not loaded. QueryPageAsync uses a stable order, Name,ID, and a page size of five. Reset to page zero when the database search changes; do not mistake the visible row count for the total database size.

Add DataGrid to its intended parent and name it grdProducts for this example:

PropertyExample value
IsReadOnlyTrue
CanUserSortColumnsTrue
CanUserResizeColumnsTrue
HeadersVisibleTrue
KeyColumn"ID"
Columns"Name,Stock,Price"
FilterColumn"Name"

A complete handler from Forms/MainForm.bas. The linked lesson includes its surrounding controls, declarations and helpers.

Forms/MainForm.bas
Private Sub grdProducts_SelectionChanged()
    UpdateSelectionStatus
End Sub

Properties#

Contract defaults are shown below. Where a new control has a different Designer starting value, that value is listed separately.

Left

DoubleDefault: 0

Horizontal position in device-independent points, relative to the parent container.

Range: -100000 to 100000.

Top

DoubleDefault: 0

Vertical position in device-independent points, relative to the parent container.

Range: -100000 to 100000.

Width

DoubleDefault: 120

Control width in device-independent points.

Range: 0 to 100000.

Designer starting value: 420.

Height

DoubleDefault: 32

Control height in device-independent points.

Range: 0 to 100000.

Designer starting value: 220.

MinWidth

DoubleDefault: 0

Minimum control width in device-independent points; 0 lets the parent layout choose.

Range: 0 to 100000.

MinHeight

DoubleDefault: 0

Minimum control height in device-independent points; 0 lets the parent layout choose.

Range: 0 to 100000.

MaxWidth

DoubleDefault: 100000

Maximum control width in device-independent points.

Range: 0 to 100000.

MaxHeight

DoubleDefault: 100000

Maximum control height in device-independent points.

Range: 0 to 100000.

TabIndex

LongDefault: 0

Keyboard navigation order within the parent container; lower values come first.

Range: 0 to 100000.

ZIndex

LongDefault: 0

Stacking order among sibling controls; larger values appear in front. Equal values preserve document order.

Range: -100000 to 100000.

Anchor

StringDefault: "Left,Top"Not in InspectorNot serialized

Edges kept at their authored distance when the parent resizes. Use a comma-separated combination of Left, Top, Right and Bottom; Dock overrides the effective anchor without deleting it.

Dock

StringDefault: "None"

Automatic placement within the parent: None, Left, Top, Right, Bottom or Fill. Dock overrides effective Anchor layout without deleting the stored anchors.

Margin

StringDefault: "0"

External spacing as one non-negative DIP value or Left,Top,Right,Bottom.

Visible

BooleanDefault: True

Whether the control is shown in the running application.

Enabled

BooleanDefault: True

Whether the control accepts user interaction in the running application.

HitTestVisible

BooleanDefault: True

Whether the running control participates in pointer hit testing. The control remains selectable in the Designer.

AllowDrop

BooleanDefault: False

Whether this running control accepts application drag-and-drop operations; Designer movement is separate.

DragMode

LongDefault: 0

VB control drag: 0 Manual (code starts a drag with the Drag method) or 1 Automatic (a left-button press starts a drag, and the control raises no Click, MouseDown or MouseUp for that press).

Range: 0 to 1.

DragIcon

StringDefault: ""

Case-insensitive name of a declared project image resource shown under the pointer while this control is dragged; empty shows a grey outline of the control.

Font

StringDefault: ""

Cell text font as Family|Size or Family|Size|Regular/Bold|Normal/Italic, size 6–96 DIP. Empty uses the theme font.

ForeColor

StringDefault: ""

Cell text color as #RRGGBB. Empty uses the Form or theme foreground.

BackColor

StringDefault: ""

Grid row and surface fill as #RRGGBB. Empty uses the theme fill.

AccessibleName

StringDefault: ""

Name announced by assistive technology. Empty uses the stable control Name.

Cursor

StringDefault: "Default"

Pointer shown over the control: Default, Arrow, Hand, IBeam, Cross, Wait, Help, SizeAll, SizeNS, SizeWE, SizeNWSE, SizeNESW or NotAllowed.

Opacity

DoubleDefault: 1

Visual opacity from 0 (transparent) to 1 (opaque).

Range: 0 to 1.

DesignLocked

BooleanDefault: FalseDesigner only

Prevents movement and resizing in the Designer without changing runtime interaction.

AccessibleDescription

StringDefault: ""

Additional help text announced by assistive technology.

AccessibleRole

StringDefault: "Auto"

Accessibility role override. Auto preserves the native semantic role; explicit values use the corresponding platform automation role.

AutomationId

StringDefault: ""

Stable automation identifier; empty uses the component Name.

TabStop

BooleanDefault: True

Whether Tab navigation can move focus to this DataGrid.

ToolTipText

StringDefault: ""

Help text shown when the pointer rests over the running control; empty disables the tooltip.

Tag

StringDefault: ""

Application-defined text associated with this control; McBasic™ does not interpret it.

RowHeight

DoubleDefault: 32

Height of each data row in device-independent points (18–200).

Range: 18 to 200.

KeyColumn

StringDefault: ""

Optional unique BindingSource column used for SelectedKey and row identity. The key column is hidden in the grid; empty shows all columns.

Columns

StringDefault: ""

Visible BindingSource columns in display order, separated by commas. Write name|Header to show a header caption, for example status|Status,due_date|Due date; the grid still binds, edits and saves through the column name. Empty generates all columns; KeyColumn stays hidden.

FilterColumn

StringDefault: ""

Column searched by the local filter. Empty searches visible columns. Only rows already loaded in the BindingSource are searched.

FilterText

StringDefault: ""

Case-insensitive text contained in loaded rows; empty disables local filtering. This does not filter or page the SQLite provider.

Loading

BooleanDefault: False

Shows the loading state while BASIC is fetching a BindingSource. Clear when the asynchronous operation finishes.

LoadingText

StringDefault: "Loading…"

Message shown while Loading is true, unless ErrorText is set.

EmptyText

StringDefault: "No rows"

Message shown when the bound result has zero rows and no loading or error state is active.

ErrorText

StringDefault: ""

Nonempty error message shown over the grid until BASIC clears it. Errors take priority over loading and empty states.

IsReadOnly

BooleanDefault: True

When false, cell text is validated against the existing BindingSource value kind and kept in its in-memory edit buffer.

CanUserSortColumns

BooleanDefault: True

Allows local column sorting in the standard DataGrid.

CanUserResizeColumns

BooleanDefault: True

Allows local column resizing in the standard DataGrid.

HeadersVisible

BooleanDefault: True

Shows column headers for the bound result.

AlternatingRowBackColor

StringDefault: ""

Background of every second row as #RRGGBB; empty paints all rows alike.

GridLines

StringDefault: "Both"

Lines between cells: None, Horizontal (between rows), Vertical (between columns) or Both.

FrozenColumns

LongDefault: 0

Number of leftmost columns that stay in place when the grid scrolls sideways.

Range: 0 to 1000.

ShowRowNumbers

BooleanDefault: False

Shows 1-based row numbers in a header column. HeadersVisible still controls the column headers.

Index

LongDefault: -1Read only in BASICDesigner Index row

Position of this control in its control array, 0 to 32767. Several controls share one name only when every one of them has an Index. Absent from the layout, and -1 in code, when the control is not in an array.

Designer values: 0 to 32767. Clear the dedicated Index row for a non-array control; BASIC then reads -1.

Events and parameters#

Replace control with the object’s Name when creating a handler. ByRef arguments may be changed by your handler; ByVal arguments report an input value.

SelectionChanged

Occurs after the effective selection changes.

Signature — see the complete lesson for an implementation
Private Sub control_SelectionChanged()

No parameters.

CellClick

Occurs once for a pressed data cell; indexes are zero-based source-row and visible-column indexes.

Signature — see the complete lesson for an implementation
Private Sub control_CellClick(ByVal RowIndex As Integer, ByVal ColumnIndex As Integer)
ParameterTypeDirection
RowIndexIntegerByVal
ColumnIndexIntegerByVal

CellDoubleClick

Occurs for a double-clicked data cell; indexes are zero-based source-row and visible-column indexes.

Signature — see the complete lesson for an implementation
Private Sub control_CellDoubleClick(ByVal RowIndex As Integer, ByVal ColumnIndex As Integer)
ParameterTypeDirection
RowIndexIntegerByVal
ColumnIndexIntegerByVal

CellBeginEdit

Occurs before cell editing starts; set Cancel to True to prevent editing.

Signature — see the complete lesson for an implementation
Private Sub control_CellBeginEdit(ByVal RowIndex As Integer, ByVal ColumnIndex As Integer, ByRef Cancel As Boolean)
ParameterTypeDirection
RowIndexIntegerByVal
ColumnIndexIntegerByVal
CancelBooleanByRef

CellEndEdit

Occurs after cell editing finishes, whether committed or cancelled.

Signature — see the complete lesson for an implementation
Private Sub control_CellEndEdit(ByVal RowIndex As Integer, ByVal ColumnIndex As Integer)
ParameterTypeDirection
RowIndexIntegerByVal
ColumnIndexIntegerByVal

CellValueChanged

Occurs after a committed data cell value changes; indexes are zero-based.

Signature — see the complete lesson for an implementation
Private Sub control_CellValueChanged(ByVal RowIndex As Integer, ByVal ColumnIndex As Integer)
ParameterTypeDirection
RowIndexIntegerByVal
ColumnIndexIntegerByVal

CurrentCellChanged

Occurs when keyboard navigation or pointer input changes the current cell.

Signature — see the complete lesson for an implementation
Private Sub control_CurrentCellChanged()

No parameters.

RowEnter

Occurs when the current cell enters a different zero-based source row.

Signature — see the complete lesson for an implementation
Private Sub control_RowEnter(ByVal RowIndex As Integer)
ParameterTypeDirection
RowIndexIntegerByVal

RowLeave

Occurs when the current cell leaves a zero-based source row.

Signature — see the complete lesson for an implementation
Private Sub control_RowLeave(ByVal RowIndex As Integer)
ParameterTypeDirection
RowIndexIntegerByVal

ColumnHeaderClick

Occurs for a completed column-header click, even when user sorting is disabled; ColumnIndex is zero-based.

Signature — see the complete lesson for an implementation
Private Sub control_ColumnHeaderClick(ByVal ColumnIndex As Integer)
ParameterTypeDirection
ColumnIndexIntegerByVal

Sorting

Occurs before local user sorting; set Cancel to True to keep the current row order.

Signature — see the complete lesson for an implementation
Private Sub control_Sorting(ByVal ColumnIndex As Integer, ByRef Cancel As Boolean)
ParameterTypeDirection
ColumnIndexIntegerByVal
CancelBooleanByRef

Sorted

Occurs after an accepted local user sort has updated the grid view.

Signature — see the complete lesson for an implementation
Private Sub control_Sorted(ByVal ColumnIndex As Integer)
ParameterTypeDirection
ColumnIndexIntegerByVal

DataError

Occurs when cell conversion or binding rejects a value; set Handled to True to suppress the standard error presentation.

Signature — see the complete lesson for an implementation
Private Sub control_DataError(ByVal RowIndex As Integer, ByVal ColumnIndex As Integer, ByVal Message As String, ByRef Handled As Boolean)
ParameterTypeDirection
RowIndexIntegerByVal
ColumnIndexIntegerByVal
MessageStringByVal
HandledBooleanByRef

DragEnter

Occurs when runtime drag data enters this control; set Effect to Copy, Move, Link or None.

Signature — see the complete lesson for an implementation
Private Sub control_DragEnter(ByVal Data As DragData, ByRef Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
DataDragDataByVal
EffectDragEffectByRef
XDoubleByVal
YDoubleByVal

DragOver

Occurs while runtime drag data moves over this control; Effect may be updated for the current position.

Signature — see the complete lesson for an implementation
Private Sub control_DragOver(ByVal Data As DragData, ByRef Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
DataDragDataByVal
EffectDragEffectByRef
XDoubleByVal
YDoubleByVal

DragOver

Occurs while a control dragged inside the app (DragMode or the Drag method) moves over this control: State is 0 when it enters, 2 while it moves over and 1 when it leaves; Source is the dragged control and X, Y are local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_DragOver(ByVal Source As Control, ByVal X As Single, ByVal Y As Single, ByVal State As Integer)
ParameterTypeDirection
SourceControlByVal
XSingleByVal
YSingleByVal
StateIntegerByVal

DragLeave

Occurs when runtime drag data leaves this control without a drop.

Signature — see the complete lesson for an implementation
Private Sub control_DragLeave()

No parameters.

Drop

Occurs when runtime drag data is dropped on this control with a stable McBasic™ effect and local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_Drop(ByVal Data As DragData, ByVal Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
DataDragDataByVal
EffectDragEffectByVal
XDoubleByVal
YDoubleByVal

DragDrop

Occurs when a control dragged inside the app (DragMode or the Drag method) is released over this control; Source is the dragged control and X, Y are local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_DragDrop(ByVal Source As Control, ByVal X As Single, ByVal Y As Single)
ParameterTypeDirection
SourceControlByVal
XSingleByVal
YSingleByVal

MouseDown

Occurs when a pointing-device button is pressed over this control; Button is stable McBasic™ identity and X/Y are control-local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_MouseDown(ByVal Button As MouseButton, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
ButtonMouseButtonByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

MouseUp

Occurs when a pointing-device button is released for this control; Button is stable McBasic™ identity and X/Y are control-local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_MouseUp(ByVal Button As MouseButton, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
ButtonMouseButtonByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

MouseMove

Occurs when the pointer moves over the logical McBasic™ control; Button contains the currently held buttons and X/Y are local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_MouseMove(ByVal Button As MouseButtons, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
ButtonMouseButtonsByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

MouseEnter

Occurs once when the pointer enters the effective bounds of the logical McBasic™ control.

Signature — see the complete lesson for an implementation
Private Sub control_MouseEnter()

No parameters.

MouseLeave

Occurs once when the pointer leaves the effective bounds of the logical McBasic™ control.

Signature — see the complete lesson for an implementation
Private Sub control_MouseLeave()

No parameters.

MouseWheel

Occurs for normalized pointer-wheel input; Delta is portable, and X/Y are local DIP coordinates.

Signature — see the complete lesson for an implementation
Private Sub control_MouseWheel(ByVal Delta As Double, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
ParameterTypeDirection
DeltaDoubleByVal
ShiftKeyModifiersByVal
XDoubleByVal
YDoubleByVal

GotFocus

Occurs once when the DataGrid receives effective keyboard focus.

Signature — see the complete lesson for an implementation
Private Sub control_GotFocus()

No parameters.

LostFocus

Occurs once when the DataGrid loses effective keyboard focus.

Signature — see the complete lesson for an implementation
Private Sub control_LostFocus()

No parameters.

KeyDown

Occurs when a physical key is pressed while this control owns effective keyboard focus; setting Handled suppresses normal processing.

Signature — see the complete lesson for an implementation
Private Sub control_KeyDown(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
ParameterTypeDirection
KeyCodeKeyCodeByVal
ShiftKeyModifiersByVal
HandledBooleanByRef

KeyPress

Occurs for committed Unicode text input; set Handled to suppress the control default.

Signature — see the complete lesson for an implementation
Private Sub control_KeyPress(ByVal Character As String, ByRef Handled As Boolean)
ParameterTypeDirection
CharacterStringByVal
HandledBooleanByRef

KeyUp

Occurs when a physical key is released while this control owns effective keyboard focus; setting Handled suppresses normal processing.

Signature — see the complete lesson for an implementation
Private Sub control_KeyUp(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
ParameterTypeDirection
KeyCodeKeyCodeByVal
ShiftKeyModifiersByVal
HandledBooleanByRef

Methods#

SetFocus

Method contract
Sub SetFocus()

Call on your instance: grdProducts.SetFocus.

Source baseline 20f4bfed6b · Build manifest