Sharing data between forms

R

Red Green

I am trying to switch to C# from Delphi and I am having some trouble finding
some information. What I need to do should be simple but I have been through
a dozen books and done web searches that don't help me out at all. Delphi
had a data module that was shared between an applications forms but I don't
see any way to do this in C#.

Lets say I have two forms, the first with a data grid and the second with
field that should contain the data coresponding to the selected record in
the grid. The second form requires setting the query parameter before
showing the data. Because of the way that C# seems to work (each form has
it's own connection and data components) I don't understand how to get the
two forms or data sets to communicate with each other.

This seems like it should be a very common thing to do, is there an example
anywhere showing how to do this?
 
W

William Ryan eMVP

Set a property or properties in each form and make them public. Set the
public property and then you can access it from any form.

Or , create a class with static properties...then set the property
corresponding tot he data you'll need. If you set them as public static,
they'll be visible by every object in the project.
 
R

Red Green

OK I understand how to make a variable public and I have tested it.

The part I don't understand is how to get the value I need to set it to. If
the datagrid has the 3 rd row highlighted that corresponds to a record in
the dataset and a field in that record has the value that I need to get for
the parameter of the dependent query. In Delphi the current record in the
dataset bound to the grid is the one selected in the grid. Is this the case
in C# and if so how do I get that value?

In Delphi it would be
ThisVar := DM1.Qry1FieldName.Value;
DM1.Qry2.Parameters[1].Value := ThisVar;

Where DM1 is the name of the datamodule, Qry1 is the Ado query that is bound
to the datagrid and FieldName is the name of the Data Field with the value
required.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top