INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

DataGrid

Populate a FlexGrid or Sheridan DataGrid by Bubbler
Posted: 15 Dec 03

This example demonstrates how to Populate a FlexGrid or Sheridan DataGrid:

Public Function LoadRecordSetIntoGrid(ctlGrid As MSFlexGrid, _
   rs As ADODB.Recordset) As Boolean

    Dim sTmp As String
    Dim vArr As Variant
    Dim i As Integer
    
    On Error GoTo ErrorHandler
    
    'first we have to clear the grid from previous query results
    '**** remove existing grid rows
    ctlGrid.Rows = 2
    ctlGrid.AddItem ""
    ctlGrid.RemoveItem 1
    
    If Not rs.EOF And Not rs.BOF Then
        'get the recordset into a string delimiting the fields
        'with a tab character and the records with a semicolon
        'replace nulls with a space
        sTmp = rs.GetString(adClipString, , Chr(9), ";", " ")

        'split the string into an array of individual records
        vArr = Split(sTmp, ";")
        
        'now add the records to the grid
        For i = 0 To UBound(vArr) - 1
            ctlGrid.AddItem vArr(i)
        Next
        'set the return value
        LoadRecordSetIntoGrid = True
    Else
        LoadRecordSetIntoGrid = False
        Exit Function
    End If
    
    'remove empty rows
    If ctlGrid.Rows > 2 Then
        On Error Resume Next 'get over removing a single record
         For i = 1 To ctlGrid.Rows - 1
            If ctlGrid.TextMatrix(i, 1) = "" Then
                ctlGrid.RemoveItem i
            Else
                Exit For
            End If
        Next
    End If

    Exit Function
ErrorHandler:
    
    LoadRecordSetIntoGrid = False
End Function

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close