Results 1 to 4 of 4

Thread: VB6 - Unbound DBGrid Data Entry

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    VB6 - Unbound DBGrid Data Entry

    Background

    I see a lot of people trying to use the flexgrid controls (the old MSFlexGrid or the newer MSHFlexGrid controls) for data entry. They really were never intended for this. Even the VB6 manual suggests that you might want to do this in some circumstances, but the process involves fairly clunky floating of a manually created and managed Marquee Textbox over the grid.


    Better Choices

    Much of the time though, you can simply use the other grids provided with VB6 that were intended to be used for data entry: the DBGrid (DAO) or DataGrid (ADO, Unicode) controls. But many people either don't understand and fear data binding or simply can't use data binding. They need a grid that works in unbound modes like the flexgrids do.

    Well if you need an unbound data entry grid and Unicode isn't a requirement, the older DBGrid works fine in unbound mode. Sadly the Unicode DataGrid doesn't support an unbound mode, probably because Microsoft found out that most programmers didn't really use DBGrids unbound anyhow.

    In some cases the flexgrid controls may offer things you actually need, so you're back to floating a marquee Textbox around. But most of the time you don't need a flexgrid!


    Why Don't People Use Unbound DBGrids?

    I suspect there are several reasons for this:
    • Most people program by copy/paste, and don't read the manuals. There is a dearth of examples on the Web for them to copy/paste from.
    • The DBGrid documentation was left out of the VB6 manuals, and you have to go back to the VB5 or even VB4 maunals, which most people don't have or also won't read.
    • This means the DBGrid documentation was also left out of the MSDN Library documentation, both on the Web and on the MSDN CDs for VB6. You have to use the old VB5-era .HLP file for this control, and most people will never think to look there.
    • The programming model for Unbound DBGrids is like that of a custom DataSource control, and foreign to many programmers.

    We can't convince people to read manuals (this is a lost cause). And if they don't even have them even the willing and able can't do so.

    But we can plop another copy/paste demo out here on the Web!


    The Demo

    This demo (attached) sets many of its DBGrid's properties at design time. However it sets up the column layout at runtime based on an INI file. This isn't required, and you can readily define your DBGrid columns in the IDE instead. For real programs you generally would do this in the IDE, but sometimes you want runtime flexibility too.

    Beyond this column layout INI, the program loads/stores using a TXT file in VB's Write#/Input# (CSV-like) format with a little twist to handle storing quotes (") in String fields that normally can't have them. Users can enter quotes in the grid but load & store swap between quotes and vbFormFeed characters, a handy trick.

    You should be able to just un-ZIP the attachment, open the VBP file, and Run.

    The source code has comments to help you understand it, but for details you might want to crack open that DBGRID32.HLP file!


    Demo Operations

    The Form in the demo has some labels with a few basic instructions on how to use special keystrokes in a data entry grid. I find that most people are a bit clueless about ESC & DEL keys and grid navigation (arrow keys, and TAB if you enable it in the grid).

    I avoided Splits entirely here, because that seems to be an even more foreign topic to those who don't work with grid-based applications extensively.


    In Conclusion

    When you want a data entry grid your best choice is a data-bound DataGrid control. If you insist on or must use an unbound data entry grid the DBGrid makes a good choice. However you do sacrifice Unicode capabilities - seldom a real problem anyway though since most other VB6 controls are not Unicode aware either.

    So here is another example people can use to try to deal with grid-based data entry without creating a rat's nest of Marquee-management code and a bunch of buttons for things like "add row," "delete row," "cancel pending changes," and so on.

    Digging deep, I did find this other example out there too: http://www.vb-helper.com/howto_dbgrid_unbound.html

    Perhaps having both will help you figure things out!
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Feb 9th, 2012 at 10:36 PM.

  2. #2
    New Member
    Join Date
    Apr 2013
    Posts
    1

    Re: VB6 - Unbound DBGrid Data Entry

    This was a very useful example. I liked the ini approach very much! Thank you very much for posting this!

  3. #3
    Lively Member
    Join Date
    Mar 2015
    Posts
    104

    Re: VB6 - Unbound DBGrid Data Entry

    Just wondered if there is a way of loading small pictures in say column one? Thanks for the code example.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - Unbound DBGrid Data Entry

    As far as I know DBGrid only supports text.

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