Applications with multiple forms often use a centralized data access architecture in which database connections and data components are shared across forms. However, configuring these shared components at design time can be challenging. For example, accessing live data through a shared database connection or using a centralized data module may require additional code to manage references between forms.
InterForm technology in dotConnect for MongoDB addresses these challenges by letting components on different forms within a Windows Forms (WinForms) application reference one another at design time. It enables shared database connections, centralized data access, and cross-form component references without additional code, while maintaining a centralized application architecture.
This article explains how InterForm works, its requirements and limitations, and how to use it in WinForms applications.
InterForm lets you create references to components located on other forms directly in the Visual Studio designer.
To create a cross-form reference, select the component's reference property in the Properties window, click the dropdown button, and locate the required component in the tree.
When you select a component, dotConnect for MongoDB performs two actions:
A virtual link consists of the form name, component name, and, optionally, the name of a nested component.
For example, if a DataLink component references the table1 table
in the dataSet1 MongoDBDataSet component located on the MyForm form,
the virtual link has the following format:
When the referencing component is loaded at design time or run time, dotConnect for MongoDB attempts to resolve the virtual link to the actual component.
null. When the form containing the referenced component is opened, the reference is restored. When that form is closed, the reference is set to null again.InterForm supports properties that reference the following component types:
When a component on a base form is referenced from another form, the reference points to the component on the base form. If you create a derived form, the reference continues to point to the original component on the base form rather than the corresponding component on the derived form.
For InterForm references to work correctly, the following requirements must be met:
InterForm technology has the following limitations:
For applications that use InterForm, we recommend placing shared data access components on a dedicated form. Create this form before other forms at run time and keep it open in the Visual Studio designer. This approach centralizes data access components, simplifies their configuration, and helps prevent reference resolution issues.
The following examples demonstrate common scenarios where InterForm can be useful.
Applications with multiple forms often need to share a single database connection. Without InterForm, you typically need to pass the connection between forms programmatically, which limits the ability to configure and use it at design time. InterForm lets you configure a shared MongoDBConnection component and reference it from other forms.
To share a connection:
You can then manage the connection settings in one location while retaining design-time access to the shared connection.
In applications with multiple forms, several controls may need to use the same data source. InterForm works with the DataLink component to provide shared data access across forms. For the configuration steps, see the Use Case section of DataLink Component Architecture.
DataLink Component Architecture | MongoDBConnection Class | MongoDBDataSet Class