Xojo DataGrid Online Guide
Description
The DataGrid component for Xojo Desktop development platform is a support tool for view and manage data in a grid.
The guide is divided into these sections:
Properties
Methods
Events
Enumerations
EnumAlignment
Defines the type of alignment of the contents in a cell.
EnumCellType
Defines the type of cell, how it will be displayed.
EnumCheckBoxValues
Defines the type of value that will be considered for CheckBox type cells.
EnumFocusCellBorderType
Defines the type of border displayed for the cell focus.
EnumFooterValueType
Defines the type of footer displayed.
Classes
The component contains two classes that specify the columns and rows.
They are:
Each of these classes contains a set of properties that will allow you to best format your columns and rows.
Property descriptions
AllowMovableColumns As Boolean
Allows you to choose whether the columns are movable.
AllowResizableColumns As Boolean
Allows you to choose whether columns are resizable.
AutoHideScrollbars As Boolean
Allows you to set if the scrollbars are visible or not.
CellBorder As Boolean
Allows you to set whether the cell has a border or not.

CellPadding As Integer
Allows you to set the space between the border and the cell content.

CheckBoxBorderSize As Integer
Allows you to set the border size of the CheckBox.

CheckBoxSize As Integer
Allows you to set the size of the CheckBox.

ColorCellBorder As Color
Allows you to set the border color of the cell.

ColorCellFocusBorder As Color
Allows you to set the border color of the cell that has the focus.

ColorCheckBoxBack As Color
Allows you to set the background color of the CheckBox.

ColorCheckBoxBackAlt As Color
Allows you to set the background color of the CheckBox in alternate rows.

ColorCheckBoxBorder As Color
Allows you to set the border color of the CheckBox.

ColorCheckBoxBorderAlt As Color
Allows you to set the border color of the CheckBox in alternate rows.

ColorCheckBoxFlag As Color
Allows you to set the flag color of the CheckBox.

ColorCheckBoxFlagAlt As Color
Allows you to set the flag color of the CheckBox in alternate rows.

ColorFooterBack As Color
Allows you to set the footer background color.

ColorFooterBorder As Color
Allows you to set the footer border color.

ColorFooterText As Color
Allows you to set the footer text color.

ColorGridBack As Color
Allows you to set the background color of the grid. (beyond cells)

ColorGridBorder As Color
Allows you to set the outer border color of the grid.

ColorHeaderBack As Color
Allows you to set the header background color.

ColorHeaderBorder As Color
Allows you to set the header border color.

ColorHeaderDrag As Color
Allows you to set the color of the column move placeholder.
ColorHeaderSortIcon As Color
Allows you to set the color of the sort icon.

ColorHeaderText As Color
Allows you to set the header text color.

ColorLink As Color
Allows you to set the text color of links.

ColorLinkAlt As Color
Allows you to set the text color of links in alternate rows.

ColorLinkSelected As Color
Allows you to set the text color of links in selected rows.

ColorProgressbar As Color
Allows you to set the color of progressbars.

ColorProgressbarBorder As Color
Allows you to set the border color of progressbars.

ColorRowsBack As Color
Allows you to set the background color of row.

ColorRowsBackAlt As Color
Allows you to set the background color of row in alternate rows.

ColorRowsBackSelected As Color
Allows you to set the background color of row in the selected rows.

ColorRowsText As Color
Allows you to set the text color of row.

ColorRowsTextAlt As Color
Allows you to set the text color of row in the alternate rows.

ColorRowsTextSelected As Color
Allows you to set the text color of row in the selected rows.

ColorScrollbarsBack As Color
Allows you to set the background color of the scrollbars.

ColorScrollbarsBackOver As Color
Allows you to set the background color of the scrollbars when then mouse is over

ColorScrollbarsBorder As Color
Allows you to set the border color of the scrollbars.

ColorScrollbarsRect As Color
Allows you to set the background color of the scrollbar cursor.

ColorScrollbarsRectOver As Color
Allows you to set the background color of the scrollbar cursor when the mouse is over.

ColumnLastSelected As Integer
Returns the last selected column.
ColumnNames As String
It's a String containing the list of column caption separated by commas.
BaDataGrid1.ColumnNames = "Id,Name,Surname,Address,City,Country,Phone"
Columns() As BaDataGridColumn
It's an Array of type BaDataGridColumn that represents the list of columns loaded in the grid.
For Each objCol As BaDataGridColumn In BaDataGrid1.Columns
System.DebugLog("Column - Index: " + objCol.Idx.ToString + " - FieldName: " + objCol.FieldName)
Next objCol
ColumnsVisible As Integer
Returns the number of visible columns in the grid.
ColumnViewStart As Integer
Returns the index of the first visible column in the grid.
ColumnWidths As String
It's a String containing a list of column widths separated by commas.
BaDataGrid1.ColumnWidths = "30,100,100,250,120,120,70"
Container As DesktopContainer
Set DesktopContainer control if the component is into a Container. If the component is directly inside a Windows you have to leave it to Nil.
DbKeyFieldName As String
Allows you to set the name of the key field of the table.
This is for when data is updated.
BaDataGrid1.DbKeyFieldName = "AN02_ID"
DbSource As Database
It allows you to set up a Database object that you will use to load data into the grid.
You can set up all Xojo compatible databases, such as: SQLite, MySQL, PostgreSQL, MS SQL, ODBC, etc.
'### SET DATABASE SOURCE ###
If Self.DbSqlLite = Nil Then
self.DbSqlLite = New SQLiteDatabase
End If
self.DbSqlLite.DatabaseFile = GetFolderItem( txtDatabase.text, FolderItem.PathTypeNative)
BaDataGrid1.DbSource = self.DbSqlLite
DbTableName As String
Allows you to set the name of the table.
This is for when data is updated.
BaDataGrid1.DbTableName = "AN02_CONTACTS"
DefaultFooterHeight As Integer
Allows you to set the default footer height.

DefaultHeaderHeight As Integer
Allows you to set the default header height.

DefaultRowHeight As Integer
Allows you to set the default row height.

EditingEnable As Boolean
Allows you to set whether the grid is editable or not. Default is False (not editable).
If you set the value to True you will indicate that the entire grid is editable. In this case you will then have to define for each column which you do not want to be editable.
The DbTableName and DbKeyFieldName properties to allow the grid to update the correct table and record.
FocusCellBorder As Boolean
Allows you to set whether the selected cell should have the focus border.

FocusCellBorderType As EnumFocusCellBorderType
Allows you to set the focus border type of the selected cell.

FontBold As Boolean
Allows you to set whether the grid font should be bold.
This parameter will be overridden by the same column property (if set).
FontItalic As Boolean
Allows you to set whether the grid font should be italic.
This parameter will be overridden by the same column property (if set).
FontName As String
Allows you to set the grid font name.
This parameter will be overridden by the same column property (if set).
FontSize As Integer
Allows you to set the grid font size.
This parameter will be overridden by the same column property (if set).
FontUnderline As Boolean
Allows you to set whether the grid font should be underline.
This parameter will be overridden by the same column property (if set).
GridBackground As Boolean
Allows you to set whether the grid has a Background.
If set to True, the ColorGridBack property will be used to color the background.

GridBorder As Boolean
Allows you to set whether the grid has a Border.
If set to True, the ColorGridBorder property will be used to color the border, and GridBorderSize for the border with.

GridBorderSize As Integer
Allows you to set whether the border width.

HasFooter As Boolean
Allows you to set if footer is visible.
If set to True, then the Footer will appear at the bottom of the grid.

LicenseCode As String
Allows you to set the license code.
You need to set the license code and license email to the Opening() event.
BaDataGrid1.LicenseEmail = "your-email@your-domain.com"
BaDataGrid1.LicenseCode = "your-license-code"
LicenseEmail As String
Allows you to set the license email.
You need to set the license code and license email to the Opening() event.
BaDataGrid1.LicenseEmail = "your-email@your-domain.com"
BaDataGrid1.LicenseCode = "your-license-code"
LinkFontBold As Boolean
Allows you to set whether the link font should be bold.
This parameter will be overridden by the same column property (if set).
LinkFontItalic As Boolean
Allows you to set whether the link font should be italic.
This parameter will be overridden by the same column property (if set).
LinkFontName As String
Allows you to set the link font name.
This parameter will be overridden by the same column property (if set).
LinkFontSize As Integer
Allows you to set the link font size.
This parameter will be overridden by the same column property (if set).
LinkFontUnderline As Boolean
Allows you to set whether the link font should be underline.
This parameter will be overridden by the same column property (if set).
MinimumColumnResizing As Integer
Allows you to set the minimum column width value when resizing columns.
MouseWheelHorizontalEnabled As Boolean
Allows you to enable or disable horizontal scrolling of the grid with the mouse wheel or trackpad.
MouseWheelVerticalEnabled As Boolean
Allows you to enable or disable vertical scrolling of the grid with the mouse wheel or trackpad.
ReleaseDate As DateTime
Returns the release date of this component.
ReleaseVersion As String
Returns the release version of this component.
RowLastSelected As Integer
Returns the last selected row.
Rows() As BaDataGridRow
It's an Array of type BaDataGridRow that represents the list of rows loaded in the grid.
RowsBackground As Boolean
Allows you to set whether rows have a background.
If set to True, the ColorRowsBack, ColorRowsBackAlt and ColorRowsBackSelected properties will be used to color the background.

RowViewEnd As Integer
Returns the last visible row in the grid.
RowViewStart As Integer
Returns the first visible row in the grid.
ScrollbarsBorder As Boolean
Allows you to set whether scrollbars have a border or not.

ScrollbarsPadding As Integer
Allows you to set the space between the border and the scrollbar cursor.
The total scrollbars size is ScrollbarsSize + ScrollbarsPadding.

ScrollbarsRounded As Integer
Allows you to set the roundness of the scrollbar cursor.

ScrollbarsSize As Integer
Allows you to set the thickness of the scrollbar cursor.
The total scrollbars size is ScrollbarsSize + ScrollbarsPadding.

TimeSelectEnd As DateTime
Returns the end time of execution of the SelectSQL method
TimeSelectStart As DateTime
Returns the start time of execution of the SelectSQL method
Method descriptions
AutoDarkLightMode ()
To auto change all grid colors with O.S. theme color.
You could call this method in the Opening event of the Wondow.
'On "Opening" Event
BaDataGrid1.AutoDarkLightMode
DeleteAllRowsSelected (boolDelRowsFromDatabase as Boolean = True)
Delete all rows selected. You can choose if delete only in view or also in database from boolDelRowsFromDatabase parameter.
Var d As New MessageDialog
Var b As MessageDialogButton
d.IconType = MessageDialog.IconTypes.Question
d.ActionButton.Caption = "Ok"
d.CancelButton.Visible = True
d.CancelButton.Caption = "Cancel"
d.Message = "Do you want to delete all rows selected?"
d.Explanation = "You are about to delete all rows selected only from grid view."
b = d.ShowModal
Select Case b
Case d.ActionButton
BaDataGrid1.DeleteAllRowsSelected(False)
Case d.AlternateActionButton
Case d.CancelButton
End Select
DeleteRowSelected (boolDelRowFromDatabase as Boolean = True)
Delete row selected. You can choose if delete only in view or also in database from boolDelRowFromDatabase parameter.
Var d As New MessageDialog
Var b As MessageDialogButton
d.IconType = MessageDialog.IconTypes.Question
d.ActionButton.Caption = "Ok"
d.CancelButton.Visible = True
d.CancelButton.Caption = "Cancel"
d.Message = "Do you want to delete the row selected?"
d.Explanation = "You are about to delete the row selected only from grid view."
b = d.ShowModal
Select Case b
Case d.ActionButton
BaDataGrid1.DeleteRowSelected(False)
Case d.AlternateActionButton
Case d.CancelButton
End Select
GetColumnFromField (strFieldName As String) As BaDataGridColumn
Get column object from field name.
Var objCol As BaDataGridColumn
objCol = BaDataGrid1.GetColumnFromField("AN02_EMAIL")
System.DebugLog("Column - Index: " + objCol.Idx.ToString + " - FieldName: " + objCol.FieldName)
GetColumnFromXY (x as Integer, y as Integer) As BaDataGridColumn
Get column object from X and Y mouse position.
Var objCol As BaDataGridColumn
objCol = BaDataGrid1.GetColumnFromXY(300, 100)
System.DebugLog("Column - Index: " + objCol.Idx.ToString + " - FieldName: " + objCol.FieldName)
GetLayout () As String
Get current layout in a Json string
Var strJson As String
strJson = BaDataGrid1.GetLayout()
System.DebugLog("strJson: " + strJson)
GetRowFromXY (x as Integer, y as Integer) As BaDataGridRow
Get row object from X and Y mouse position.
Var objRow As BaDataGridRow
objRow = BaDataGrid1.GetRowFromXY(100, 300)
System.DebugLog("Row - Index: " + objRow.Idx.ToString + " - Db.Id: " + objRow.DbRow.Column("AN02_ID").StringValue)
RowAdd (objJsonData as JSONItem)
Add a record in the database by passing a JSON.
Var strJson As String = ""
strJson = strJson + "{" + EndOfLine
strJson = strJson + " ""FIELD01"": ""Value 01""," + EndOfLine
strJson = strJson + " ""FIELD02"": 0," + EndOfLine
strJson = strJson + " ""FIELD03"": true," + EndOfLine
strJson = strJson + " ""FIELD04"": 1.99" + EndOfLine
strJson = strJson + "}" + EndOfLine
Var objJson As New JSONItem(strJson)
BaDataGrid1.RowAdd(objJson)
RowAdd (vFieldKeyValue as Variant)
Add a record in the database by passing the Value of Key Field.
Var varValue As Variant = "VALUE01"
BaDataGrid1.RowAdd(varValue)
RowAddSelect (idxRow as Integer)
Add a row to selected rows from index value.
objRow = BaDataGrid1.RowAddSelect(6)
RowsDeselectAll ()
Deselect all rows.
objRow = BaDataGrid1.RowsDeselectAll()
RowSelect (idxRow as Integer)
Select a row form index value.
objRow = BaDataGrid1.RowSelect(8)
RowsSelectAll ()
Select all rows.
objRow = BaDataGrid1.RowsSelectAll()
RowUpdate (objRow as BaDataGridRow, objCol as BaDataGridColumn, strFieldName as string, varFieldValue as Variant, strNumberFormat as string = "-0.000")
Update a record in the database by code.
Use strNumberFormat param only if field is numeric
BaDataGrid1.RowUpdate(objRow, objCol, "AN01_NAME", "Robert")
BaDataGrid1.RowUpdate(objRow, objCol, "AN01_FINALPRICE", 99.55, "-0.00")
SelectSQL (strSql as String)
Execute as query string where the SQL command is strSql parameter.
'### SET QUERY SQL ###
Var StrSQL As String = ""
StrSQL = StrSQL + "select " + EndOfLine
StrSQL = StrSQL + "AN02_ID, AN02_SEL, AN02_COLOR, AN02_EMAIL, AN02_PROGRESS, AN02_SURNAME, AN02_NAME" + EndOfLine
StrSQL = StrSQL + ", AN02_BIRTHDAY, AN02_INDGENDER, AN02_URL" + EndOfLine
StrSQL = StrSQL + "from AN02_CONTACTS" + EndOfLine
StrSQL = StrSQL + "order by AN02_ID asc" + EndOfLine
'### SET COLUMNS WIDTH ###
Var sColWidth As String = ""
sColWidth = sColWidth + "50," 'AN02_ID
sColWidth = sColWidth + "40," 'AN02_SEL
sColWidth = sColWidth + "50," 'AN02_COLOR
sColWidth = sColWidth + "200," 'AN02_EMAIL
sColWidth = sColWidth + "120," 'AN02_PROGRESS
sColWidth = sColWidth + "150," 'AN02_SURNAME
sColWidth = sColWidth + "150," 'AN02_NAME
sColWidth = sColWidth + "100," 'AN02_BIRTHDAY
sColWidth = sColWidth + "100," 'AN02_INDGENDER
sColWidth = sColWidth + "200," 'AN02_URL
BaDataGrid1.ColumnWidths = sColWidth
'### SET COLUMNS CAPTION ###
Var sColNames As String = ""
sColNames = sColNames + "Id,"
sColNames = sColNames + "Sel.,"
sColNames = sColNames + "Color,"
sColNames = sColNames + "Email,"
sColNames = sColNames + "Progress,"
sColNames = sColNames + "Surname,"
sColNames = sColNames + "Name,"
sColNames = sColNames + "Birthday,"
sColNames = sColNames + "Gender,"
sColNames = sColNames + "Url,"
BaDataGrid1.ColumnNames = sColNames
'### SET TABLE NAME (for data Update) ###
BaDataGrid1.DbTableName = "AN02_CONTACTS"
'### SET KEY FIELD NAME (for data Update) ###
BaDataGrid1.DbKeyFieldName = "AN02_ID"
'### EXECUTE SQL QUERY ###
BaDataGrid1.SelectSQL(StrSQL)
SetLayout (strJson as String, boolSort as Boolean = False)
Set current layout from a Json string
Var strJson As String
strJson = LoadFromFile()
BaDataGrid1.SetLayout(strJson)
ShowGrid ()
Show data grid with result data.
objRow = BaDataGrid1.ShowGrid()
ShowSettings ()
Show settings grid, with column and properties about data.
objRow = BaDataGrid1.ShowSettings()
Sort (objCol As BaDataGridColumn, bAddColumnSorting As Boolean = False)
Sort result data with column object. You can choose if order by column or if add column to last columns ordered.
'to set first ordered column
Var objCol As BaDataGridColumn = BaDataGrid1.Columns(5)
objCol.Sorted = True
objCol.SortedAscending = True
BaDataGrid1.Sort(objCol)
'to add second ordered column
Var objCol2 As BaDataGridColumn = BaDataGrid1.Columns(3)
objCol2.Sorted = True
objCol2.SortedAscending = False
BaDataGrid1.Sort(objCol2, True) 'pass True as the second parameter
Event descriptions
CellClick (x As Integer, y As Integer, objRow As BaDataGridRow, objCol As BaDataGridColumn) As Boolean
This event fires when you click the mouse in a grid cell.
The X position of the mouse cursor.
The Y position of the mouse cursor.
The objRow parameter returns the row object (BaDataGridRow).
The objCol parameter returns the column object (BaDataGridColumn).
CellDoubleClick (x As Integer, y As Integer, objRow As BaDataGridRow, objCol As BaDataGridColumn) As Boolean
This event fires when you double click the mouse in a grid cell.
The X position of the mouse cursor.
The Y position of the mouse cursor.
The objRow parameter returns the row object (BaDataGridRow).
The objCol parameter returns the column object (BaDataGridColumn).
CellValueChanged (varOldVal as Variant, varNewVal as Variant, objCol As BaDataGridColumn, objRow As BaDataGridRow) As Boolean
This event fires when the value of a cell changes.
The varOldVal parameter represents the previous cell value.
The varNewVal parameter represents the new cell value.
The objCol parameter returns the column object (BaDataGridColumn).
The objRow parameter returns the row object (BaDataGridRow).
If you return True the operation is canceled.
System.DebugLog CurrentMethodName _
+ " - OldVal: " + varOldVal.StringValue _
+ " - NewVal: " + varNewVal.StringValue _
+ " - FieldName: " + objCol.FieldName
'If you return True the operation is canceled
'Return True
DarkLightModeChanged ()
This event fires after AutoDarkLightMode method is called, after changed all colors.
'Inside the event, that is after all the colors have been changed, you can choose whether to change anything else.
BaDataGrid1.ColorLink = &cFF000000
BaDataGrid1.ColorProgressbar = &c0096FF00
DatabaseDeleteAllRowsError (strFieldKeyName as String, strIdxsList as String, objRowsToDelete() As BaDataGridRow, intError As Integer, strError As String, strQueryDelete as String)
This event fires after method DeleteAllRowsSelected() when an error occurs.
The strFieldKeyName parameter returns the key field name.
The strIdxsList parameter returns the comma-separated list of indexes of the rows it tried to delete.
The objRowsToDelete() parameter returns an Array objects of rows (BaDataGridRow) that it tried to delete.
The intError returns Integer Error value.
The strError returns String Error value.
The strQueryDelete returns the SQL command used.
System.DebugLog CurrentMethodName _
+ " - strFieldKeyName: " + strFieldKeyName _
+ " - sIdxsList: " + strIdxsList _
+ " - Error: " + intError.ToString + " - " + strError
System.DebugLog "strQueryDelete:"
System.DebugLog strQueryDelete
DatabaseDeleteRowError (strFieldKeyName as String, varFieldKeyValue as Variant, objRowToDelete As BaDataGridRow, intError As Integer, strError As String, strQueryDelete as String)
This event fires after method DeleteRowSelected() when an error occurs.
The strFieldKeyName parameter returns the key field name used.
The varFieldKeyValue parameter returns the key field value used.
The objRowToDelete parameter returns a row (BaDataGridRow) that it tried to delete.
The intError returns Integer Error value.
The strError returns String Error value.
The strQueryDelete returns the SQL command used.
System.DebugLog CurrentMethodName _
+ " - strFieldKeyName: " + strFieldKeyName _
+ " - varFieldKeyValue: " + varFieldKeyValue.StringValue _
+ " - ID RowToDelete: " + objRowToDelete.DbRow.ColumnAt(0).StringValue _
+ " - Error: " + intError.ToString + " - " + strError
System.DebugLog "strQueryDelete:"
System.DebugLog strQueryDelete
DatabaseInserted ()
This event fires when a record is inserted.
Typically in this event the code to go to end of grid is used.
BaDataGrid1.RowSelectLastRecord()
DatabaseInsertedError (intError as Integer, strError as String, strQueryInsert as String)
This event fires when you try to insert a record in the database but an error occurs.
The intError returns Integer Error value.
The strError returns String Error value.
The strQueryInsert returns the SQL command used.
System.DebugLog CurrentMethodName _
+ " - Error: " + intError.ToString + " - " + strError
System.DebugLog strQueryInsert
DatabaseUpdated (strFieldKeyName as String, varFieldKeyValue as Variant, objCol as BaDataGridColumn, objRow as BaDataGridRow, varNewValue as Variant)
This event fires when the database is updated.
The strFieldKeyName parameter returns the key field name updated.
The varFieldKeyValue parameter returns the key field value updated.
The objCol parameter returns the current column (BaDataGridColumn) updated.
The objRow parameter returns the current row (BaDataGridRow) updated.
The varNewValue returns Variant new value.
System.DebugLog CurrentMethodName _
+ " - strFieldKeyName: " + strFieldKeyName _
+ " - varFieldKeyValue: " + varFieldKeyValue.StringValue _
+ " - varNewValue: " + varNewValue.StringValue.StringValue _
+ " - objCol.FieldName: " + objCol.FieldName
DatabaseUpdateError (strFieldKeyName as String, varFieldKeyValue as Variant, objCol as BaDataGridColumn, objRow as BaDataGridRow, intError as Integer, strError as String, strQueryUpdate as String)
This event fires when you try to update the database but an error occurs.
The strFieldKeyName parameter returns the key field name used.
The varFieldKeyValue parameter returns the key field value used.
The objCol parameter returns the column (BaDataGridColumn) used.
The objRow parameter returns the row (BaDataGridRow) used.
The intError returns Integer Error value.
The strError returns String Error value.
The strQueryUpdate returns the SQL command used.
System.DebugLog CurrentMethodName _
+ " - strFieldKeyName: " + strFieldKeyName _
+ " - varFieldKeyValue: " + varFieldKeyValue.StringValue _
+ " - Error: " + intError.ToString + " - " + strError
System.DebugLog strQueryUpdate
FooterCellBackgroundPaint (picFooter as Picture, objCol as BaDataGridColumn) As Boolean
This event fires before a footer cell is redrawn. (redraw background)
The picFooter parameter returns the graphic object to draw on.
The objCol parameter returns the current column (BaDataGridColumn).
If you return True the picFooter object will overlap the header cell.
If you return False (or you don't use the event), then it will not be redrawn.
If objCol.FieldName = "AN02_NAME" Then
picFooter.Graphics.DrawingColor = &cFF930000
picFooter.Graphics.FillRectangle (picFooter.Graphics.Width/2), 5, 15, 15
picFooter.Graphics.DrawingColor = &cFEFEFE00
picFooter.Graphics.DrawLine (picFooter.Graphics.Width/2), 5, (picFooter.Graphics.Width/2)+15, 20
Return True
End If
FooterCellPaint (picFooter as Picture, objCol as BaDataGridColumn) As Boolean
This event fires after a header cell is redrawn. (redraw over)
The picFooter parameter returns the graphic object to draw on.
The objCol parameter returns the current column (BaDataGridColumn).
If you return True the picFooter object will overlap the header cell.
If you return False (or you don't use the event), then it will not be redrawn.
If objCol.FieldName = "AN02_NAME" Then
picFooter.Graphics.DrawingColor = &cFF930000
picFooter.Graphics.FillRectangle (picFooter.Graphics.Width/2), 5, 15, 15
picFooter.Graphics.DrawingColor = &cFEFEFE00
picFooter.Graphics.DrawLine (picFooter.Graphics.Width/2), 5, (picFooter.Graphics.Width/2)+15, 20
Return True
End If
GenericError (strMethodName as String, intErrorNumber as Integer, strErrorMessage as String)
This event fires when an unhandled generic error is generated.
The strMethodName parameter returns the key field name used.
The intErrorNumber returns Integer Error value.
The strErrorMessage returns String Error value.
System.DebugLog CurrentMethodName _
+ " - strMethodName: " + strMethodName _
+ " - Error: " + intErrorNumber.ToString + " - " + strErrorMessage
HeaderCellBackgroundPaint (picHeader as Picture, objCol as BaDataGridColumn) As Boolean
This event fires before a header cell is redrawn. (redraw background)
The picHeader parameter returns the graphic object to draw on.
The objCol parameter returns the current column (BaDataGridColumn).
If you return True the picHeader object will overlap the header cell.
If you return False (or you don't use the event), then it will not be redrawn.
If objCol.FieldName = "AN02_NAME" Then
picHeader.Graphics.DrawingColor = &cFF930000
picHeader.Graphics.FillRectangle (picHeader.Graphics.Width/2), 5, 15, 15
picHeader.Graphics.DrawingColor = &cFEFEFE00
picHeader.Graphics.DrawLine (picHeader.Graphics.Width/2), 5, (picHeader.Graphics.Width/2)+15, 20
Return True
End If

HeaderCellPaint (picHeader as Picture, objCol as BaDataGridColumn) As Boolean
This event fires after a header cell is redrawn. (redraw over)
The picHeader parameter returns the graphic object to draw on.
The objCol parameter returns the current column (BaDataGridColumn).
If you return True the picHeader object will overlap the header cell.
If you return False (or you don't use the event), then it will not be redrawn.
If objCol.FieldName = "AN02_NAME" Then
picHeader.Graphics.DrawingColor = &cFF930000
picHeader.Graphics.FillRectangle (picHeader.Graphics.Width/2), 5, 15, 15
picHeader.Graphics.DrawingColor = &cFEFEFE00
picHeader.Graphics.DrawLine (picHeader.Graphics.Width/2), 5, (picHeader.Graphics.Width/2)+15, 20
Return True
End If

LinkCalled (strUrl as String, objCol as BaDataGridColumn, objRow as BaDataGridRow) As Boolean
This event fires when a link cell is clicked.
The strUrl parameter returns the cell value.
The objCol parameter returns the column object (BaDataGridColumn).
The objRow parameter returns the row object (BaDataGridRow).
Select Case objCol.FieldName
Case "AN02_URL"
ShowURL(strUrl)
Case "AN02_EMAIL"
ShowURL("mailto:" + strUrl)
End Select
'If you want break selection return true value
Return True
MouseDown (x as Integer, y as Integer)
This event fires while the mouse button is being held down.
The x and y parameters represent the cursor position.
MouseEnter ()
The mouse has entered the area of the control.
MouseExit ()
The mouse has left the area of the control.
MouseMove (x as Integer, y as Integer)
The mouse has moved within the control.
The x and y parameters represent the cursor position.
MouseUp (x as Integer, y as Integer)
The mouse button was released.
The x and y parameters represent the cursor position.
Opening ()
The control is about to be displayed. Use this event to initialize a control.
The Opening event is called after the Constructor.
You need to set the license code and license email to the Opening() event.
BaDataGrid1.LicenseEmail = "your-email@your-domain.com"
BaDataGrid1.LicenseCode = "your-license-code"
QueryExecuted strQuerySql as String
This event fires after the SelectSQL() method.
The strQuerySql parameter returns the SQL string used.
RowDeleted (idxRowDeleted as Integer, objRowDeleted as BaDataGridRow, boolDelRowFromDatabase as Boolean)
This event fires after the DeleteRowSelected() method.
The idxRowDeleted parameter returns the index of the deleted row.
The objRowDeleted parameter returns the object (BaDataGridRow) of the deleted row.
The boolDelRowFromDatabase parameter returns whether the row was chosen to be deleted from the database as well.
System.DebugLog CurrentMethodName _
+ " - idxRowDeleted: " + idxRowDeleted.ToString _
+ " - ID: " + objRowDeleted.DbRow.ColumnAt(0).StringValue
RowsCellBackgroundPaint (picCell as Picture, objCol as BaDataGridColumn, objRow as BaDataGridRow) As Boolean
This event fires before a grid cell is redrawn. (redraw background)
The picCell parameter returns the graphic object to draw on.
The objCol parameter returns the current column (BaDataGridColumn).
The objRow parameter returns the current row (BaDataGridRow).
If you return True the picCell object will overlap the grid cell.
If you return False (or you don't use the event), then it will not be redrawn.
If objCol.FieldName = "AN02_SURNAME" Then
picCell.Graphics.DrawingColor = &c99FF0000
picCell.Graphics.DrawOval picCell.Graphics.Width-24, 3, 20, 20
Return True
End If

RowsCellPaint (picCell as Picture, objCol as BaDataGridColumn, objRow as BaDataGridRow) As Boolean
This event fires after a grid cell is redrawn. (redraw over)
The picCell parameter returns the graphic object to draw on.
The objCol parameter returns the current column (BaDataGridColumn).
The objRow parameter returns the current row (BaDataGridRow).
If you return True the picCell object will overlap the grid cell.
If you return False (or you don't use the event), then it will not be redrawn.
If objCol.FieldName = "AN02_SURNAME" Then
picCell.Graphics.DrawingColor = &c99FF0000
picCell.Graphics.DrawOval picCell.Graphics.Width-24, 3, 20, 20
Return True
End If

RowsDeleted (idxsRowsDeleted as String, objRowsDeleted() as BaDataGridRow, boolDelRowFromDatabase as Boolean)
This event fires after the DeleteAllRowsSelected() method.
The idxsRowsDeleted parameter returns a comma-separated String of indexes that it tried to delete.
The objRowsDeleted() parameter returns an Array objects of rows (BaDataGridRow) that it tried to delete.
The boolDelRowFromDatabase parameter returns whether the rows was chosen to be deleted from the database as well.
RowSelected (idxRowSelected as Integer, objRowSelected as BaDataGridRow)
This event fires when a row in the grid is selected.
The idxRowSelected parameter returns the index of selected row.
The objRowSelected parameter returns the objects of row (BaDataGridRow) of selected row.
SettingsChanged ()
This event fires when the grid settings are changed.
StartDrag (x As Integer, y As Integer, objRowsDragged() As BaDataGridRow)
This event fires when the drag begins.
The parameters x and y return the cursor position.
The objRowsDragged() parameter returns an Array of selected row objects (BaDataGridRow).
In this example we use LastRowsDragged variable to save dragged rows. In this way after we can drop them in other control.
System.DebugLog CurrentMethodName
'Creates a picture to show while dragging
Var mImage As New Picture(150, 30)
mImage.Graphics.DrawingColor = &cFCFCFC00
mImage.Graphics.FillRoundRectangle 0, 0, mImage.Width, mImage.Height, 6, 6
mImage.Graphics.DrawingColor = &c33333300
mImage.Graphics.DrawRoundRectangle 0, 0, mImage.Width, mImage.Height, 6, 6
mImage.Graphics.DrawText "Total drag rows: " + objRowsDragged.Count.ToString, 10, 20
'Create DragItem object
Var d As New DragItem(Me, x+20, y+20, mImage.Width, mImage.Height)
d.Picture = mImage
d.DragPicture = mImage
Self.LastRowsDragged = objRowsDragged
'Activate dragging
d.Drag
BaDataGridColumn Class
The BaDataGridColumn class manages the properties of each column.
Var objCol As BaDataGridColumn = BaDataGrid1.Columns(0)
System.DebugLog objCol.FieldName
Immediately after calling the BaDataGrid1.SelectSQL() method all columns will inherit properties from the grid. So if you want to customize some columns you will have to do it after calling the SelectSQL method.
'### EXECUTE SQL QUERY ###
BaDataGrid1.SelectSQL(StrSQL)
'### AFTER QUERY can sets Columns property ###
BaDataGrid1.EditingEnable = True
BaDataGrid1.CheckBoxSize = 15
'AN02_ID - 0
BaDataGrid1.Columns(0).Type = BaDataGrid.EnumCellType.Number
BaDataGrid1.Columns(0).Alignment = BaDataGrid.EnumAlignment.RightMiddle
BaDataGrid1.Columns(0).TextMaxLength = 18
BaDataGrid1.Columns(0).EditingEnable = False
'AN02_SEL - 1
BaDataGrid1.Columns(1).Type = BaDataGrid.EnumCellType.CheckBox
BaDataGrid1.Columns(1).CheckBoxValues = BaDataGrid.EnumCheckBoxValues.TrueFalse
BaDataGrid1.Columns(1).Alignment = BaDataGrid.EnumAlignment.CenterMiddle
'AN02_COLOR - 2
BaDataGrid1.Columns(2).Type = BaDataGrid.EnumCellType.Color
BaDataGrid1.Columns(2).TextMaxLength = 10
'AN02_EMAIL - 3
BaDataGrid1.Columns(3).TextMaxLength = 255
BaDataGrid1.Columns(3).Type = BaDataGrid.EnumCellType.Link
'AN02_PROGRESS - 4
BaDataGrid1.Columns(4).Type = BaDataGrid.EnumCellType.ProgressBar
BaDataGrid1.Columns(4).ProgressValueMax = 310.55
BaDataGrid1.Columns(4).ProgressValueMin = 120.99
'AN02_SURNAME - 5
BaDataGrid1.Columns(5).TextMaxLength = 50
'AN02_NAME - 6
BaDataGrid1.Columns(6).TextMaxLength = 50
'AN02_BIRTHDAY - 7
BaDataGrid1.Columns(7).Type = BaDataGrid.EnumCellType.Date
BaDataGrid1.Columns(7).DateFormat = "dd/MM/YYYY"
BaDataGrid1.Columns(7).Alignment = BaDataGrid.EnumAlignment.CenterMiddle
'AN02_INDGENDER - 8
BaDataGrid1.Columns(8).Type = BaDataGrid.EnumCellType.List
BaDataGrid1.Columns(8).ListValues.Add "" '0
BaDataGrid1.Columns(8).ListValues.Add "Man" '1
BaDataGrid1.Columns(8).ListValues.Add "Woman" '2
'AN02_URL - 9
BaDataGrid1.Columns(9).TextMaxLength = 255
BaDataGrid1.Columns(9).Type = BaDataGrid.EnumCellType.Link
'### REDRAW GRID ###
BaDataGrid1.Refresh
BaDataGridColumn Properties
BaDataGridRow Class
The BaDataGridRow class manages the properties of each row.
Var objRow As BaDataGridRow = BaDataGrid1.Rows(0)
System.DebugLog objRow.Idx.ToString
Immediately after calling the BaDataGrid1.SelectSQL() method all rows will inherit properties from the grid. So if you want to customize some rows you will have to do it after calling the SelectSQL method.
The DbRow property is of type DatabaseRow. This will allow you to interact with the database row data.