Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Populate Flexigrid
Author:
Philfr & Lee Nicholson
E-mail:
Click to e-mail author
Submitted:
5/23/2004
Version:
VB6
Compatibility:
VB6
Category:
Controls
Views:
20479
Description: fills ANY Flexigrid on ANY form with data from ANY recordset. A blank TitleString causes the code to identify and name the columns with the recordset's field names. If the recordset is empty, the flexigrid is displayed with a "No Records To Display" message. The ParamArray can contain as many values as there are fields in the recordset. A zero for any value will cause the column to be hidden. I usually have the KeyField hidden in column Zero, and use the code flx(flx.MouseRow,0) to identify the record number to search on.
Declarations:
'none
Code:
'***************************************************************** ' Project: Flexigrid Library Manager ' Module: Populate ' Author: Lee Nicholson & Philfr ' Date: 29/4/2004 ' If you like the code and want to use it, please give credit to our ' work by leaving the above authorship. ' '***************************************************************** ' Modified by: ' Date: ' changes made: '***************************************************************** ' Description: fills ANY Flexigrid on ANY form with data from ANY recordset. ' A blank TitleString causes the code to identify and name the columns ' with the recordset's field names. If the recordset is empty, the ' flexigrid is displayed with a "No Records To Display" message ' The ParamArray can contain as many values as there are fields in the ' recordset. A zero for any value will cause the column to be hidden. ' I usually have the KeyField hidden in column Zero, and use the ' code flx(flx.MouseRow,0) to identify the record number to search on. ' 'Version: 2.4 '****************************************************************** Option Explicit Public Sub gFillFlexGrid(ByVal RSFG As Recordset, _ flx As MSFlexGrid, TitleString As String, SortByColumn As Integer, _ ParamArray FieldWidths()) ' May 6, 2004 ' usage: ' gFillFlexGrid adoRS, myFlex, "", 0, 1800, 2000, 0, 1000 ' |----------> unlimited ' TitleString takes the form ' "AssignID|Teacher|^Cluster|Assign Name|Due Date" Dim i As Integer, MaxRows As Integer Dim j As Integer, MaxCols As Integer On Error GoTo erh If RSFG.RecordCount > 0 Then MaxCols = RSFG.Fields.Count MaxRows = RSFG.RecordCount If TitleString = "" Then ' derive field names from recordset TitleString = RSFG.Fields(0).Name For i = 1 To MaxCols - 1 TitleString = TitleString & "|<" & RSFG.Fields(i).Name Next i End If With flx .AllowUserResizing = flexResizeColumns .Clear .FormatString = TitleString ' set the width of each field on the grid from the FieldWidth array For i = 0 To UBound(FieldWidths) .ColWidth(i) = FieldWidths(i) Next i ' set the height of each row (assumes the form's mode is in pixels) .RowHeight = TextHeight("X") + 10 .Cols = MaxCols .Rows = MaxRows + 1 .Row = 0 ' setting row 0 (Titlestring) to Bold For i = 0 To MaxCols - 1 .col = i .CellFontBold = True Next i .Font.Bold = False ' fill the rows with data from the recordset RSFG.MoveFirst j = 1 Do While Not RSFG.EOF For i = 0 To MaxCols - 1 ' to avoid an error if the field value is NULL add a blank string .TextMatrix(j, i) = RSFG.Fields(i) & "" Next i RSFG.MoveNext j = j + 1 Loop ' set grid column's to merge and sort on For i = 0 To MaxCols - 1 .MergeCol(i) = True Next i .MergeCells = flexMergeRestrictColumns .ColSel = SortByColumn .Sort = flexSortGenericAscending End With Else With flx .FormatString = "|Data Error" .ColWidth(0) = 0 .ColWidth(1) = 3000 .Cols = 2 .Rows = 2 .TextMatrix(1, 1) = "No Records To Display" End With End If Exit Sub erh: MsgBox Err.Description End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement