Returning a variable

N

Nathan Guill

I have a databound form that when a user clicks the button to add another
record, a new dialog box opens. This form requires a few pieces of
information to insure that the new record does not already exist.

What I want:

1) If the record does not exist, this form should return the new record
number
2) If the record does exist, this form should a) return a list to another
form for the user to pick which record to use which would then return that
record number
or b) return the old record number

How do I do this?
 
R

Roman Wagner

I assume that your form is able to retreive all records.

1) define an event to signal, that a new record is available.
1a) define a property in your formclass to get the new record from
or
1b) define a new eventargs class to hold a reference of the new record
2) in the clickeventhandler of your button do your logic.
2a) create a new record and emit your new event according to your
designdecision 1a or 1b
or
2b) show a new form which displays the list of all records and let the
user choose one of them. in that form provide a property RecordSelected
that holds the record selected by user. if showDialog of the
selectionform is equal to DialogResult.OK emit your event with the
value of RecordSelected

after that you can subscribe to your new event to get the new record
 
N

Nathan Guill

Okay, let me see if I can clarify this. First, know that I am self taught
in C# and this is my first Application in this language, I've only
programmed in VBA and AutoLisp before.

This function I am trying to accomplish is that when a user clicks a button,
a second form (form2) pops up and asks for some information from the user.
Once the user hits OK on form2, form2 searches my database for that
information. 2 things can happen at this point, 1) nothing is found and 2)a
list of records is found. If nothing is found, I want form 2 to add a new
record with the information the user supplied and send that record back to
the original form. If a list is found, then if that list should be returned
to the original form.

I know how to do everything needed except how to return the information back
to the original form. How is this done?
 
J

Jeff Gaines

I know how to do everything needed except how to return the information
back
to the original form. How is this done?

Set up public variables for the data you want to return, fill them with
the appropriate data when the user clicks 'OK' then read them in your main
form. Something like:

cInputBox frmNewFolder = new cInputBox("Create New Folder", "Enter name of
folder to create in " + strTargetPath, "");
if (frmNewFolder.ShowDialog() == DialogResult.OK)
{
// User pressed OK so grab data
string strNewFolder = frmNewFolder.Result;
}
else
{
// user cancelled;
}

That's copied and pasted from one of my apps where the new form is created
with some parameters. You can return what you like, a variable, an array,
struct class whatever - just set it up when the user presses 'OK'.
 

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