A DataGrid Control as a Disconnected Data Entry Tool


Author: Lothar Haensler

DataGrid Control as a Data-Entry Tool (VB6 - Maybe VB5)

Screen Shot

This sample was added after a superb response from the CodeGuru VB discussion forum. The original requirement was for a way of entering and modifying a list of data in a tabular format. Lothar suggested the use of a disconnected ADOR recordset and the DataGrid control that comes with VB6 - a simple solution that works perfectly for the job.

Firstly, you need to set a reference to Microsoft Active Data Objects Recordset 2.1 library (msador15.dll). Then add the DataGrid component into your VB6 toolbar and paste in the following code into the Form_Load event after adding a Grid (DataGrid1) to your form:



private Sub Form_Load()
    Dim r as ADOR.Recordset
    Dim lCount as Long

'
' Create a new disconnected recordset object
'
    set r = new ADOR.Recordset
'
' Setup the fields - you can use any valid type of
' ado field type for these. I've used VarChar just
' for testing / demonstration purposes.
'
    r.Fields.Append "Name", adVarChar, 10
    r.Fields.Append "Notes", adVarChar, 50
    r.CursorType = adOpenDynamic
    r.Open
    r.AddNew

    r.Fields(0).Value = "Chris"
    r.Fields(1).Value = "almost over the hill"
    r.AddNew
    r.Fields(0).Value = "Chris"
    r.Fields(1).Value = "but enjoying every minute"

    for lCount = 1 to 25
        r.AddNew
        r.Fields(0).Value = "Name " & lCount + 2
        r.Fields(1).Value = "some kind of description"
    next
'
' Populate the datagrid
'
    set DataGrid1.DataSource = r

End Sub
'
'

The attached sample shows how to add new lines to the control 'on-the-fly' and also how to query the values in the grid using another ADOR Recordset object.

Download Zipped Project file (3k)



Comments

  • Add and Delete row in Vb6 datagrid & how to create a button with in it.

    Posted by mohamouli on 06/10/2006 02:39am

    Hi, Im usign vb6 Datagrid with ADO connection property. How to add a new record to the datagrid and delete an existing one from it?. and How to create a button when i clicking datagrid columns? pls help me for the same.

    Reply
  • DataGrid Control as a Disconnected Data Entry Tool

    Posted by Legacy on 06/09/2003 12:00am

    Originally posted by: GGuerra

    I'm a brazilian software engineer.
    Thanks for this solution.
    I liked it a lot.

    Reply
  • with Combobox

    Posted by Legacy on 05/27/2003 12:00am

    Originally posted by: chetan

    i have combobox and recordset as u mentioned for disconnected dataentry
    on button click event i show the combobox.

    but it accepts a record with null values

    kindly inform how do i stop user to add new row without completing current row.

    regards

    chetan

    Reply
  • Data grid & child recordset

    Posted by Legacy on 01/25/2003 12:00am

    Originally posted by: Shan

    I have a datagrid sourced to a child recordset in the dataenvironment. How do I refer to data and add a new record to this child recordset? The child looks like an extra field in the parent recordset but I cant work out how to add a new record and fill it from code 
    
    Regards shan

    Reply
  • select field in DBGird

    Posted by Legacy on 01/25/2003 12:00am

    Originally posted by: Shan

    I am using an ado datagrid to display recordsources. The datagrid populates with the correct recordsource. I need to know how to select individual records from the datagrid. I have a "product ID" field that I would like to use as a search criteria once the user selects a particular record in the datagrid. 
    
    the "product id" will be used to pull information from the database about the product and populate another form with that products information.

    Does anyone know how to do this?

    Shan

    Reply
  • selecting fields in vb6 datagrid

    Posted by Legacy on 09/13/2002 12:00am

    Originally posted by: devon

    I'm working on a database project and I am using an ado datagrid to display recordsources. The datagrid populates with the correct recordsource. I need to know how to select individual records from the datagrid. I have a "product ID" field that I would like to use as a search criteria once the user selects a particular record in the datagrid.

    the "product id" will be used to pull information from the database about the product and populate another form with that products information.

    Does anyone know how to do this?


    Thanks

    devon1974x@yahoo.com

    • datagrid control help

      Posted by wwywnp on 01/21/2010 02:34am

      I'm working on a Interface project and I am using a datagrid to display user edit text. How do I need to do?

      Reply
    Reply
  • selecting fields in vb6 datagrid

    Posted by Legacy on 09/13/2002 12:00am

    Originally posted by: devon

    I'm working on a database project and I am using an ado datagrid to display recordsources. The datagrid populates with the correct recordsource. I need to know how to select individual records from the datagrid. I have a "product ID" field that I would like to use as a search criteria once the user selects a particular record in the datagrid. 
    
    

    the "product id" will be used to pull information from the database about the product and populate another form with that products information.

    Does anyone know how to do this?


    Thanks

    devon1974x@yahoo.com

    Reply
  • Datagrid with a child recordset. How to use?

    Posted by Legacy on 04/13/2002 12:00am

    Originally posted by: ted

    I have a datagrid sourced to a child recordset in the dataenvironment. How do I refer to data and add a new record to this child recordset? The child looks like an extra field in the parent recordset but I cant work out how to add a new record and fill it from code
    Regards Ted

    Reply
  • CheckBox

    Posted by Legacy on 05/23/2000 12:00am

    Originally posted by: Jimbo

    How do I present boolean data as a checkbox. I've played around with the datagrid formating properties and had no success.

    Reply
  • Comment

    Posted by Legacy on 02/18/2000 12:00am

    Originally posted by: TrangVo

    Your code is simple, good for someone who wants to create un recordset.
    
    Thank you!

    But I have a question about it!!!
    If I build the first field (=key) and doesn't want to change the value when I point to this field!!just the second field is able to change value!How we do it?

    If you could find the way, can you tell me how?

    Thank,

    DTV

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Live Event Date: September 17, 2014 @ 2:00 p.m. ET In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device types and data …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds