A DataGrid Control as a Disconnected Data Entry Tool
Author: Lothar Haensler
DataGrid Control as a Data-Entry Tool (VB6 - Maybe VB5)

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.

Comments
Add and Delete row in Vb6 datagrid & how to create a button with in it.
Posted by mohamouli on 06/10/2006 02:39amDataGrid Control as a Disconnected Data Entry Tool
Posted by Legacy on 06/09/2003 12:00amOriginally posted by: GGuerra
I'm a brazilian software engineer.
ReplyThanks for this solution.
I liked it a lot.
with Combobox
Posted by Legacy on 05/27/2003 12:00amOriginally 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
Replyselect field in DBGird
Posted by Legacy on 01/25/2003 12:00amOriginally posted by: Shan
ReplyData grid & child recordset
Posted by Legacy on 01/25/2003 12:00amOriginally posted by: Shan
Replyselecting fields in vb6 datagrid
Posted by Legacy on 09/13/2002 12:00amOriginally 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
-
Replydatagrid control help
Posted by wwywnp on 01/21/2010 02:34amI'm working on a Interface project and I am using a datagrid to display user edit text. How do I need to do?
Replyselecting fields in vb6 datagrid
Posted by Legacy on 09/13/2002 12:00amOriginally posted by: devon
ReplyDatagrid with a child recordset. How to use?
Posted by Legacy on 04/13/2002 12:00amOriginally 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
ReplyRegards Ted
CheckBox
Posted by Legacy on 05/23/2000 12:00amOriginally 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.
ReplyComment
Posted by Legacy on 02/18/2000 12:00amOriginally posted by: TrangVo
Reply