Re: Passing a Parameter to a Form when Opening

From: Saurabh (saurabh_at_nagpurcity.net)
Date: 02/18/04


Date: Wed, 18 Feb 2004 15:30:45 -0000

I ma not sure I understand your problem. There are 2 steps in displaying a
form.
1) Create a form object
2) Display the form

Between step 1 and 2, you can set the properties of the form, so if you
create your form, set whatever you want to pass into the object, you can see
that value in the load event of the form.

example class :
public class MyForm : Form
{
    public int MyValueToLookInLoadEvent = 0;
    public MyForm()
    {
    }

    private void MyForm_Load( object sender, System.EventArgs e)
    {
        if (MyValueToLookInLoadEvent == 1)
            DoSomething();
        else
            DoSomethingElse();
    }
}

example main code
MyForm f = new MyForm();
f.MyValueToLookInLoadEvent = 1;
f.Show();

thats about it.

I guess you will need to decide what you want in MyValueToLookInLoadEvent
and the datatype of it, and other things. You can also have an overloaded
constructor of the form taking a parameter.

Sorry for the C# code, i know you are after VB.NET. Anyways, HTH,

--Saurabh

"Suresh rao" <srao@issgroup.net> wrote in message
news:1238f01c3f632$2459abc0$a001280a@phx.gbl...
> I have the same issue.
> You could either define class member variable and public
> or internal.
>
> I have read the documentation and there is no way that i
> know of to pass parameters to forms in WinForms.
> But i am relatively new to Win Forms (mostly worken on
> Web Forms)
>
> If anyone has something better , please send it to me.
> >-----Original Message-----
> >I have a form called frmCustSearch to search for
> customers against an SQL
> >Server database.
> >
> >The form contains a simple textbox into which the
> Customers surname is
> >typed, and a datagrid then becomes visible on the form
> containing the
> >CustID, Surname, Forename and address of all people with
> that surname.
> >
> >The correct customer is then selected from the datagrid
> and I want to open a
> >new form called frmCustomer to display all the details
> for that customer,
> >using the CustID as an argument when opening the form so
> that it can
> >retrieve the customer record from the database during
> its load event.
> >
> >This is similar to using the OpenArgs in MS Access.
> >But how do I achieve this in VB.NET?
> >Your help is much appreciated.
> >
> >Paul
> >
> >
> >.
> >



Relevant Pages

  • RE: Making one field on a form dependent on another fields results
    ... use an AutoNumber field type for the primary key. ... If your customer changes their name or address, ... > ColumnWidths How much horizontal space to allow for display of the column. ... > textbox with its control source set to the Position field. ...
    (microsoft.public.access.forms)
  • RE: Combo Box
    ... customer name with every record. ... So, to display the name and abbreviation on your form, either base your form ... "Brook" wrote: ... > lookup/dropdown for the Quality, and with the quality is chosen with is ...
    (microsoft.public.access.forms)
  • Re: Pull Downs
    ... is the data in Combo2 from the same table as combo1? ... was customer a and customer b with same business names by chance, ... then it should display two records. ...
    (microsoft.public.access.forms)
  • Re: ComboBox display
    ... Some of the items entered are longer than I have space to display on the ... You can use the AfterUpdate event of the combo box to write the full text ... assign a customer to that line of data. ... So use a combo box and put a Box control on top of the dropdown ...
    (microsoft.public.access.forms)
  • Re: Doing work after the window has displayed.
    ... you will need to use a separate thread to do the ... Otherwise your users cannot interact with the form once the process starts. ... > MyForm mf = new MyForm; ... > doesn't display before processing starts. ...
    (microsoft.public.dotnet.framework.windowsforms)