Unbound Virtual Grid Population

Garry Lowther

3rd September 2001


 

Build 5.00.090 has easy to use functions to bind a SQL statement to a grid to provide:

 

 

The techniques demonstrated here should be used for all grids which can be fully populated from a SQL statement.

 

The following new functions are now available:

 

 

DataWidgets.InitialiseUnboundGrid (dwGrid As SSDBGrid, sCaption as string)

 

DataWidgets.PopulateGridFromSQLQuery (dwGrid As SSDBGrid, sSQL as String)

 

 

Note: the word unbound derives from the 3 modes that the data grid can operate:

 

A simple example demonstrates how to add an unbound grid to view all companies:

 

Public Sub Form_AfterLoad()

 

      Set dwGrid = FormObjectsLocal.ShowForm.GetFieldWidget( _

            EntityName”, “GridFieldName”)

      if dwGrid is nothing then exit sub

 

      With DataWidgets

            .InitialiseUnboundGrid (dwGrid), “All Companies”

            .PopulateGridFromSQLQuery (dwGrid), “Select * From Company”

      End With

End Sub

 

Not only can the grid now efficiently process very large recordsets, but it also automatically provides column sorting:  by right mouse clicking on the column header.

 

Warning: Column sorting is very generic so you must obey an important rule when writing your SQL query. This rules relates to fields of type TEXT in SQL Server. TEXT fields cannot be sorted unless cast to a VARCHAR data type. For example the JobTitle column should be written as:

 SELECT….. Convert(Varchar(64), JobTitle) as JobTitle …. FROM….

This will ensure that sorting the JobTitle column will be efficiently processed.

 

It is normal to add your own style to columns (width, type etc..) and this should be done using DataWidgets.AddColumnToGrid before calling DataWidgets.PopulateGridFromSQLQuery.