Results 1 to 4 of 4

Thread: VB6 Databinding with the DataGrid (used as a Read-Only RowPicker)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    VB6 Databinding with the DataGrid (used as a Read-Only RowPicker)

    Not much to comment, other than what the Title says.

    More common in such scenarios are perhaps MS-HFlexGrids,
    but those don't support real DataBinding and are slower, because the
    Recordset-Data has to be taken over "as a copy" when a HFlex is used.

    The VB6-DataGrid on the other hand, is the only "List-Control" we
    have in VB6, which is a true "virtual one" (the Data is kept outside the
    Control - in an ADO-Recordset - and then only the visible Rows are rendered).

    There's a small "Details-Form" which is shown as a ToolWindow (non-modally),
    which then follows the currently clicked Record of the DataGrid in the other Form,
    "automagically" due to Binding to the same Recordset (over the Text-Detail-Fields
    in the other Form).

    Thanks to dilettante for his HFlex-based Demo, where I've stolen the Form-Layout for the ToolForm.

    The one thing one has to keep in mind, when using a VB6-DataGrid in such a "bound mode" is,
    that it behaves with much less "quirks", when it's used in "Batch-Mode" - meaning:
    - the ADO-Rs has to use a clientside cursor
    - and it should be opened with the Flags: adOpenStatic, adLockBatchOptimistic

    With that in place, there's not much it complains about.

    The other thing not well-known about the DataGrid is perhaps, how to switch it into
    true "Read-Only-Mode" (showing full Row-Selections - and never entering its Edit-Cell-Mode):
    - set the Grids "AllowUpdates"-Property to False
    - lock the Default-SplitView (at Form_Load-Time) with: DataGrid.Splits(0).Locked = True

    Then it will look like in the following ScreenShot:



    Here's the Demo-Source: DataGridPicker.zip

    Have fun.

    Olaf

  2. #2
    New Member
    Join Date
    Jan 2017
    Posts
    3

    Re: VB6 Databinding with the DataGrid (used as a Read-Only RowPicker)

    Hi Olaf,

    Thanks for this - i´m trying to use it with your sqlite wrapper against a memory db.
    This works really fast and i have also managed to update the RS from the grid.
    What i do not get to work, is to scroll the grid to the position of eg. a RS.FindNext.
    How can this be done?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: VB6 Databinding with the DataGrid (used as a Read-Only RowPicker)

    Quote Originally Posted by Marko8 View Post
    Hi Olaf,

    Thanks for this - i´m trying to use it with your sqlite wrapper against a memory db.
    This works really fast and i have also managed to update the RS from the grid.
    What i do not get to work, is to scroll the grid to the position of eg. a RS.FindNext.
    How can this be done?
    The DataSource needs to be manually synchronized after such actions as Rs.FindFirst/Next - e.g.:
    Code:
    Private Sub cmdFind_Click()
      If Rs.FindFirst("ID=" & txtID.Text) Then 'when the ID was found in the cRecordset
         Dim DS As ADODB.Recordset
         Set DS = DG.DataSource
             DS.AbsolutePosition = Rs.AbsolutePosition 'synchronize the Positions manually
      Else
         MsgBox "a Record with ID: " & txtID.Text & " doesn't exist"
      End If
    End Sub
    Here's an example, which demonstrates that (nearly identical to the ADO-based version in the opener-post,
    but using SQLite): DataGridPickerSQLite.zip

    I've also added a new AutoSync-mechanism (for the opposite direction) in new RC5-version 5.0.57,
    which ensures that a given Rs.AbsolutePosition will follow along with the actions on its derived DataSource,
    so you might want to update to the newest version, if you want to use that.

    Olaf

  4. #4
    New Member
    Join Date
    Jan 2017
    Posts
    3

    Re: VB6 Databinding with the DataGrid (used as a Read-Only RowPicker)

    Quote Originally Posted by Schmidt View Post
    I've also added a new AutoSync-mechanism (for the opposite direction) in new RC5-version 5.0.57,
    which ensures that a given Rs.AbsolutePosition will follow along with the actions on its derived DataSource,
    so you might want to update to the newest version, if you want to use that.
    Olaf
    Thank you, this is very helpful!
    With v 57 i get now RS_move events when moving through the datagrid, so i know the current position without silly workarounds.

    PS: you forgot to update the website, it still says version 5.0.55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width