Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: How to populate componentOne TrueDbgrid with data without using ADODC control.


Message #1 by th3wav3@y... on Thu, 18 Jul 2002 04:03:30
Any changes made to data in a TDBGrid bound in storate mode to an XArrayDB
will be automatically reflected in the XArrayDB.  Changes made to data in an
XArrayDB, however, are not automatically reflected in the TDBGrid -- you
must either Refresh, ReBind, or ReOpen the grid in order to update the
display.

If you set the grid's AllowAddNew, AllowDelete and/or AllowUpdate properties
to true, your user can add rows, delete rows, and edit your data directly in
the TDBGrid, and changes will be reflected in the XArrayDB.

Pete

-----Original Message-----
From: Olivier [mailto:monmar1@b...]
Sent: Thursday, July 18, 2002 6:37 PM
To: professional vb
Subject: [pro_vb] RE: How to populate componentOne TrueDbgrid with data
without using ADODC control.


I have some problems Updating the Grid and the Array.
Actually, when I want to add or delete a row, I do it in the XarrayDB and
then ReBind the TDBG
But, when I want to edit Data, I edit the value MyArray(Row,Col) in a text
box and then, refresh the TDBG.
But it doesn't work properly.
My Grid is emptied when I add a row afterwards.

What is my problem ?? Can you help me ?

Another problem appeared to me :
When I delete the last row of the Grid, all the rows were deleted.
My solution is that I added TDBG.Bookmark = Null before the TDBG.ReBind,
it seems to work.

Thanks for your Help Guys !

Olivier

> Sure -- get your data in any way you want, and put it into an XArrayDB.
Set
your TDBGrid's .DataMode property to Storage.  You'll need to include a
Project, Reference to ComponentOne XArrayDB Object.

In your code, load the XArrayDB, then bind the TDBGrid to it.  This example
is taking data from a local Recordset that was populated via an ODBC call
to
SQL Server, putting each row's fields into module-level variants (good
practice for loading data into an XArrayDB), then loading each field into
the XArrayDB:

Private mRecordset As Recordset

' variants for loading XArrayDB
Private mvDescription As Variant
Private mvEffectiveDate As Variant
Private mvLastUpdatedAt As Variant

' XArrayDB (will be bound to TDBGrid)
Private mXArrayDB As New XArrayDB

' XArrayDB constants
Private Const INITIAL_ARRAY_LBOUND As Integer = 0
Private Const INITIAL_ARRAY_UBOUND As Integer = -1

' XArrayDB column constants
Private Const XA_DESCRIPTION As Integer = 0
Private Const XA_EFFECTIVE_DATE As Integer = 1
Private Const XA_LAST_UPDATED_AT As Integer = 2
Private Const XA_FIRST_COL As Integer = XA_DESCRIPTION
Private Const XA_LAST_COL As Integer = XA_LAST_UPDATED_AT

'...then after the recordset is loaded:
Dim i As Integer

    With mRecordset
        i = 0
	  .MoveFirst
        While Not .EOF
            mvDescription = !Description
            mvEffectiveDate = !EffectiveDate
            mvLastUpdatedAt = !LastUpdatedAt

            mXArrayDB.ReDim INITIAL_ARRAY_LBOUND, i, XA_FIRST_COL,
XA_LAST_COL

            mXArrayDB(i, XA_DESCRIPTION) = mvDescription
            mXArrayDB(i, XA_EFFECTIVE_DATE) = mvEffectiveDate
            mXArrayDB(i, XA_LAST_UPDATED_AT) = mvLastUpdatedAt
            .MoveNext
            i = i + 1
        Wend
    End With

    ' rebind TDBGrid to XArrayDB (to refresh TDBGrid display)
    With TDBGrid1
        .Array = mXArrayDB
        .Bookmark = Null
        .ReBind
    End With
    DoEvents

The above code was snatched in pieces from an existing project, with
variables renamed to make things more obvious...I haven't actually run the
above code, so cannot guarantee that its bug-free.

HTH, Pete


---
Visual C# - A Guide for VB6 Developers
This book will make it easy to transfer your skills
from Visual Basic 6 to C#, the language of choice
of the .NET Framework.
http://www.wrox.com/ACON11.asp?ISBN=1861007175&p2p0059



  Return to Index