[dba-VB] C# Emulate the Access subform

Charlotte Foust cfoust at infostatsystems.com
Thu Mar 4 10:45:45 CST 2010


There are a variety of ways to do it, John.  The simplest I've found is to create a usercontrol with whatever controls I need on it, grid, listview, textboxes, whatever.  The usercontrol usually has a public method called FillData with arguments for the values needed to sync the usercontrol to the parent form. When we use FillData, the subform fills its own datasource using the arguments passed in.  This acts pretty much like the master/child links in Access.

An alternative is to fill the dataset at the parent form and simply pass a datarow to the usercontrol.  Or possibly the entire dataset if you're using a grid.  You would only do that when the subform is causing changes to the parent form because they share fields.  Not an ideal situation but one that happens sometimes.  We most commonly run into the need when we have a grid that includes a button to popup a child form.  Since changes to the child form also changes the data displayed in the grid (which shows a subset of information), we pass the datarow to the child form so that the changes are automatically made as if a ByRef were being used.

Charlotte Foust

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Thursday, March 04, 2010 5:24 AM
To: VBA
Subject: [dba-VB] C# Emulate the Access subform

I like the Access main form / subform paradigm.  I am trying to figure out how to do that in C#, 
probably using a DataGridView as the subform.

I assume that you guys do something like this.  I need to know how you do the parent/child link 
thing to cause the parent ID to automatically fill in the FK field in the child table.  Basically I 
want the user to be able to move through the main form records and have the subform automatically 
display the child records, then stop and fill in records in the subform / child table.

-- 
John W. Colby
www.ColbyConsulting.com
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com





More information about the dba-VB mailing list