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
  • 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
  • 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
  • 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

  • Although much publicity around computer security points to hackers and other outside attacks, insider threats can be particularly insidious and dangerous, whether caused by malice or employee negligence. In this report, you learn the eight most significant cybersecurity threats that could impact your organization (at any time), Forbes cited internal threats as No. 3, noting that internal attacks can be "the most devastating" due to the amount of damage privileged users can inflict and the type of data they can …

  • On-demand Event Event Date: March 19, 2015 The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility. Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private app stores to …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date