FlexGrid & ADO.Rst


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: FlexGrid & ADO.Rst

  1. #1
    challis Guest

    FlexGrid & ADO.Rst


    Hi all

    I have a situation that I am hoping that can be sped up significantly. The
    scenario is as follows:

    I have a form with a MSFlexGrid control and would like to assign it an ADODB.Recorset
    (2.5) object to use to populate the grid.
    Is this possible, or must I populate the grid manually?

    Placing a data control on the form is not out of the question, but the form/data
    control is not to access any database itself. What may be possible in this
    situation is assigning the recordset to a data control and then associate
    the grid with the data control.

    Any opinion would be appreciated. If you intend posting sample code, please
    also e-mail it to me if it's not too much trouble.

    Thanks in advance

    challis

  2. #2
    Phil Weber Guest

    Re: FlexGrid & ADO.Rst

    > I have a form with a MSFlexGrid control and would like to
    > assign it an ADODB.Recordset (2.5) object to use to populate
    > the grid. Is this possible...?


    Challis: Sure, just Set the grid's DataSource property equal to the ADO
    recordset:

    ' rs is an open and populated ADO Recordset
    Set msFlexGrid.DataSource = rs

    ---
    Phil Weber



  3. #3
    challis Guest

    Re: FlexGrid & ADO.Rst


    Hi

    I wish it were that simple

    See the code listing for the form as yet. I am busy prototyping an application.
    The data ie ADODB.Recordset will be passed from another component.

    flx is the name of the flexgrid.

    I would appreciate if you would find why the code errs. The call to LoadGrid
    works perfectly.

    challis


    Private Sub Form_Load()

    'Call LoadGrid(GetRecordset)
    Set flx.DataSource = GetRecordset


    End Sub ' Form_Load


    Private Sub Form_Resize()

    ' minimum width and height of the form
    Const conMinHeight = 3000
    Const conMinWidth = 5000

    ' differentials between the flexgrid and the
    ' forms dimensions
    Const conFlxWidthDiff = 240
    Const conflxHeightDiff = 1200

    Dim lngFormWidth As Long
    Dim lngFormHeight As Long

    With Me
    ' determine the dimensions of the form
    lngFormWidth = .Width
    If lngFormWidth < conMinWidth Then
    lngFormWidth = conMinWidth
    End If
    lngFormHeight = .Height
    If lngFormHeight < conMinHeight Then
    lngFormHeight = conMinHeight
    End If

    If Not ((.WindowState = vbMaximized) Or (.WindowState = vbMinimized))
    Then
    ' set form dimensions
    .Width = lngFormWidth
    .Height = lngFormHeight
    End If
    End With

    ' set flexgrid dimensions
    With flx
    .Width = lngFormWidth - conFlxWidthDiff
    .Height = lngFormHeight - conflxHeightDiff
    End With

    End Sub ' Form_Resize


    Private Sub LoadGrid( _
    ByVal rst As ADODB.Recordset)

    Dim strItem As String

    flx.TextArray(0) = "Number"
    flx.TextArray(1) = "Date"
    flx.TextArray(2) = "Type"
    flx.TextArray(3) = "Owner"
    flx.TextArray(4) = "StatusDate"
    flx.TextArray(5) = "Status"
    flx.TextArray(6) = "Comment"

    With rst
    .MoveFirst
    Do While Not .EOF
    strItem = _
    ![Number] & vbTab & _
    ![Date] & vbTab & _
    ![Type] & vbTab & _
    ![owner] & vbTab & _
    ![Statusdate] & vbTab & _
    ![Status] & vbTab & _
    ![comment]

    flx.AddItem strItem
    .MoveNext
    Loop
    End With

    End Sub ' LoadGrid


    Private Function GetRecordset() As ADODB.Recordset

    Dim rst As New ADODB.Recordset

    With rst
    Set .ActiveConnection = Nothing
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic
    .CursorType = adOpenKeyset

    With .Fields
    .Append "Number", adBSTR
    .Append "Date", adDate
    .Append "Type", adBSTR
    .Append "Owner", adBSTR
    .Append "StatusDate", adDate
    .Append "Status", adBSTR
    .Append "Comment", adBSTR
    End With

    .Open
    End With

    With rst
    .AddNew
    ![Number] = 1
    ![Date] = #3/3/1999#
    ![Type] = "Ad-Hoc"
    ![owner] = "challis"
    ![Statusdate] = #4/4/1999#
    ![Status] = "Test"
    ![comment] = "A test entry to display in the " & _
    "user interface grid"
    .UpdateBatch
    End With

    ' assign a function value
    Set GetRecordset = rst

    Set rst = Nothing

    End Function ' GetRecordSet


    "Phil Weber" <pweber@devx.com> wrote:
    > > I have a form with a MSFlexGrid control and would like to
    > > assign it an ADODB.Recordset (2.5) object to use to populate
    > > the grid. Is this possible...?

    >
    >Challis: Sure, just Set the grid's DataSource property equal to the ADO
    >recordset:
    >
    > ' rs is an open and populated ADO Recordset
    > Set msFlexGrid.DataSource = rs
    >
    >---
    >Phil Weber
    >
    >



  4. #4
    Phil Weber Guest

    Re: FlexGrid & ADO.Rst

    > I would appreciate if you would find why the code errs.

    Challis: Which line causes the error, and what error do you get?
    ---
    Phil Weber



  5. #5
    challis Guest

    Re: FlexGrid & ADO.Rst


    Hi

    I have reposted the code, and commented in the Form_Load procedure the errors
    that arise. The error is only generated when attemting to set the datasource
    of the flx.
    Sub LoadGrid works perfectly, but I am looking to get as much speed out of
    this operation as possible (bear in mind LoadGrid is not optimized, this
    is demo code).

    To recreate the error, create a form and stick a grid onto it. MsFlexGrid
    (sp4) and name it flx. In it's properties set the rows to 1, fixed rows to
    1, fixed columns to 0, columns to 7.
    copy and paste the code into the forms module and run the form.

    challis


    "Phil Weber" <pweber@devx.com> wrote:
    > > I would appreciate if you would find why the code errs.

    >
    >Challis: Which line causes the error, and what error do you get?
    >---
    >Phil Weber
    >
    >



    Hi

    I wish it were that simple

    See the code listing for the form as yet. I am busy prototyping an application.
    The data ie ADODB.Recordset will be passed from another component.

    flx is the name of the flexgrid.

    I would appreciate if you would find why the code errs. The call to LoadGrid
    works perfectly.

    challis


    Private Sub Form_Load()

    ' the commented line below works
    'Call LoadGrid(GetRecordset)

    ' the line below as it is would generate a runtime error
    ' 91 object variable or with block variable not set
    ' without the "Set" the error is a type mismatch(13)
    Set flx.DataSource = GetRecordset


    End Sub ' Form_Load


    Private Sub Form_Resize()

    ' minimum width and height of the form
    Const conMinHeight = 3000
    Const conMinWidth = 5000

    ' differentials between the flexgrid and the
    ' forms dimensions
    Const conFlxWidthDiff = 240
    Const conflxHeightDiff = 1200

    Dim lngFormWidth As Long
    Dim lngFormHeight As Long

    With Me
    ' determine the dimensions of the form
    lngFormWidth = .Width
    If lngFormWidth < conMinWidth Then
    lngFormWidth = conMinWidth
    End If
    lngFormHeight = .Height
    If lngFormHeight < conMinHeight Then
    lngFormHeight = conMinHeight
    End If

    If Not ((.WindowState = vbMaximized) Or (.WindowState = vbMinimized))
    Then
    ' set form dimensions
    .Width = lngFormWidth
    .Height = lngFormHeight
    End If
    End With

    ' set flexgrid dimensions
    With flx
    .Width = lngFormWidth - conFlxWidthDiff
    .Height = lngFormHeight - conflxHeightDiff
    End With

    End Sub ' Form_Resize


    Private Sub LoadGrid( _
    ByVal rst As ADODB.Recordset)

    Dim strItem As String

    flx.TextArray(0) = "Number"
    flx.TextArray(1) = "Date"
    flx.TextArray(2) = "Type"
    flx.TextArray(3) = "Owner"
    flx.TextArray(4) = "StatusDate"
    flx.TextArray(5) = "Status"
    flx.TextArray(6) = "Comment"

    With rst
    .MoveFirst
    Do While Not .EOF
    strItem = _
    ![Number] & vbTab & _
    ![Date] & vbTab & _
    ![Type] & vbTab & _
    ![owner] & vbTab & _
    ![Statusdate] & vbTab & _
    ![Status] & vbTab & _
    ![comment]

    flx.AddItem strItem
    .MoveNext
    Loop
    End With

    End Sub ' LoadGrid


    Private Function GetRecordset() As ADODB.Recordset

    Dim rst As New ADODB.Recordset

    With rst
    Set .ActiveConnection = Nothing
    .CursorLocation = adUseClient
    .LockType = adLockBatchOptimistic
    .CursorType = adOpenKeyset

    With .Fields
    .Append "Number", adBSTR
    .Append "Date", adDate
    .Append "Type", adBSTR
    .Append "Owner", adBSTR
    .Append "StatusDate", adDate
    .Append "Status", adBSTR
    .Append "Comment", adBSTR
    End With

    .Open
    End With

    With rst
    .AddNew
    ![Number] = 1
    ![Date] = #3/3/1999#
    ![Type] = "Ad-Hoc"
    ![owner] = "challis"
    ![Statusdate] = #4/4/1999#
    ![Status] = "Test"
    ![comment] = "A test entry to display in the " & _
    "user interface grid"
    .UpdateBatch
    End With

    ' assign a function value
    Set GetRecordset = rst

    Set rst = Nothing

    End Function ' GetRecordSet





  6. #6
    Phil Weber Guest

    Re: FlexGrid & ADO.Rst

    > Private Sub Form_Load()
    >
    > ' the line below as it is would generate a runtime error
    > ' 91 object variable or with block variable not set
    > ' without the "Set" the error is a type mismatch (13)
    > Set flx.DataSource = GetRecordset


    Challis: I'm sorry, I got my grids confused. The MSFlexGrid apparently
    supports binding only to an intrinsic data control or an RDO data control
    (to confirm this, try clicking on the grid's DataSource property in the
    Properties window at design time). If you use the DataGrid control instead,
    you can bind it to an ADO recordset using the above syntax.
    ---
    Phil Weber



  7. #7
    challis Guest

    Re: FlexGrid & ADO.Rst


    Thanks Phil, appreciated

    I have one more question then ...

    Can I assign an ADODB.Recordset to a datacontrol, then use it for the Flexgrid?
    Do you know how to implemnt IRowCursor or have documentation to this. I suspect
    that the FlexGrid can take an assignment to it's datasource, but expects
    an object that implements IRowCursor, ie can be casted to IROwCursor.

    challis


    "Phil Weber" <pweber@devx.com> wrote:
    > > Private Sub Form_Load()
    > >
    > > ' the line below as it is would generate a runtime error
    > > ' 91 object variable or with block variable not set
    > > ' without the "Set" the error is a type mismatch (13)
    > > Set flx.DataSource = GetRecordset

    >
    >Challis: I'm sorry, I got my grids confused. The MSFlexGrid apparently
    >supports binding only to an intrinsic data control or an RDO data control
    >(to confirm this, try clicking on the grid's DataSource property in the
    >Properties window at design time). If you use the DataGrid control instead,
    >you can bind it to an ADO recordset using the above syntax.
    >---
    >Phil Weber
    >
    >



  8. #8
    Phil Weber Guest

    Re: FlexGrid & ADO.Rst

    > Can I assign an ADODB.Recordset to a datacontrol,
    > then use it for the Flexgrid?


    Challis: No. The MSFlexGrid can bind only to DAO and RDO recordsets, not
    ADO. If you want to use an ADO recordset, you'll have to either switch to
    the VB6 DataGrid or upgrade to VideoSoft's VSFlexGrid, which is
    plug-compatible with the MSFlexGrid, but can bind to ADO recordsets.
    ---
    Phil Weber



  9. #9
    Ian Williams Guest

    Re: FlexGrid & ADO.Rst

    FYI

    The MS Heirachical FlexGrid can bind to an ADO recordset, e.g.

    Set rs = <what ever>
    Set MSHFlexGrid1.DataSource = rs
    MSHFlexGrid1.Refresh


    regards

    Ian

    ** invalid email address, change dk to denmark

    homepage http://www.kingsoft-denmark.com/
    Tips & Tricks page http://tips.kingsoft-denmark.com/

    "Phil Weber" <pweber@devx.com> wrote in message
    news:3a704431$1@news.devx.com...
    > > Can I assign an ADODB.Recordset to a datacontrol,
    > > then use it for the Flexgrid?

    >
    > Challis: No. The MSFlexGrid can bind only to DAO and RDO recordsets, not
    > ADO. If you want to use an ADO recordset, you'll have to either switch to
    > the VB6 DataGrid or upgrade to VideoSoft's VSFlexGrid, which is
    > plug-compatible with the MSFlexGrid, but can bind to ADO recordsets.
    > ---
    > Phil Weber
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center