Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to bind controls on the main form to a biz object
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00879779
Message ID:
00879794
Views:
14
Mike,

>.NET seems to want you put a dataset on the form instead of using a biz object for their data binding scheme. What's the best way to bind mm controls to an mm biz object on the main application form?

Even if the form isn't based on mmBusinessForm, you can still bind MM .NET controls to business objects with just one additional step. Here's what you need to do:

1. As you normally would, add a "using" statement for your application's business object namespace, but also add a reference to the OakLeaf.MM.Main.Business. For example:
using OakLeaf.MM.Main.Business;
using OakLeaf.MM.NorthwindSample.Main.Business;
2. As you normally would, create a field that hold a reference to the business object (this is more for the sake of convenience than an actual requirement). For example:
public class MainForm : mmMainAppForm
{
	public Orders oOrder;
3. In the form's constructor before the call to InitializeComponent, instantiate the business object, but don't use the usual "RegisterBizObj" method since the form doesn't have it...just use the "new" keyword. For example:
public MainForm()
{
	this.oOrder = new Orders();

	//
	// Required for Windows Form Designer support
	//
	InitializeComponent();
3. In the form's constructor after the call to InitializeComponent, add code that manually registers the user interface control with the business object's StateChange method. For example:
public MainForm()
{
	this.oOrder = new Orders();

	//
	// Required for Windows Form Designer support
	//
	InitializeComponent();		

	this.oOrder.StateChange += new mmBusinessStateChangeDelegate(this.mmTextBox1.StateChangeHandler);
4. As you normally would, add code to the form that calls a business object method that retrieves data from the back end. This code must be executed AFTER the instantiation of the business object and registration of the user interface controls. For example:
this.oOrder.GetOrderByOrderID(10249);
5. Now, go back to the form in design mode, and manually set the BindingSource and BindingSourceMember properties of your textbox (the BindingSource dialog won't show any business objects, but the BindingSourceMember dialog will work).

That should do it for you...when you run the form, you should see the data in your text boxes.

Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform