Is there a way to return or access a class object created inside a public partial class (form) from
I have a process that allows expenses to be added from a form, and a separate process to add an asset from a form. I would like to add a combination of the two if the expense is for an asset but to run the db inserts in the same function so that if one fails, both are rolled back. I created my second asset form to accept the values for price, purchase date, and payment type and have that only being generated when the expense type is an asset.
FrmAssetFromExpense frmAssetFromExpense = new(expenseDate, amount, type);
fromAssetFromExpense.ShowDialog();
Inside the new form for asset addition, all the items are in place to create the Asset class object from the values entered on the form.
Is there a way to return that Asset object to the main expense form to run a single sql insert?
13 Replies
Yeah. The easiest way here would be for
FrmAssetFromExpense
to expose the created object as a property
you could then do ok, so then inside the FrmAssetFromExpense form, I would need to add this CreatedAsset as a property by adding public Assets CreatedAsset {get; set;}?
yeah, but private set 🙂
dont allow it to be changed from the outside.
do I do that inside the public form class or the public partial?
never touch designer files yourself
to the designer, the cs file for the actions and values on the form
not*
yes
thats where your custom code goes.
I don't understand the question tbh, your form is a
public partial class FormWhatever : Form
there are really no alternatives to that :pone second, pulling up discord on my other machine to show you
what is the error for the CreatedAsset prop?
that my class Assets was less accessible, so I set that to public as well and that went away, but I think I need to turn a few more classes public to resolve the cascade of errors, since it impacted dropdowns, etc.
sure.
thank you for your assistance