How to access a class in a form declared public in another form

  • Thread starter Thread starter Esperanza
  • Start date Start date
E

Esperanza

Hello C# expert !

I have a class clients declared in frmMain,
Now, I want to access it in my second form named frmLoan.
Dotnet does not see it.
Why ??
thanks in advance !!

//----------------------------------------------------------------------
//Declared in frmMain

public Clients MyClients;
//----------------------------------------------------------------------


MyParent = (frmMain)this.ParentForm;
MyParent.MyClients.AddClient(strNameData, strAddressData, strPhoneData,
intAmountData,intNbrYearsData, floatInterestData, intSalaryData);

MyParent.MyClients.LoadClientList();
 
Try declaring it as

public static Clients MyClients;

instead (assuming, of course, that there is no chance that frmLoan could be
instantiated first). Then just access it like:
frmMain.MyClients;

Steve
 
Esperanza said:
I have a class clients declared in frmMain,
Now, I want to access it in my second form named frmLoan.
Dotnet does not see it.
Why ??
thanks in advance !!

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(It's not generally a good idea to have public variables anyway, to be
honest...)
 
Back
Top