Binding a Windows Client Control Add-in to the Database

Similar to other field controls on a page, a Microsoft Dynamics NAV Windows client control add-in can bind with data in the Dynamics NAV database. This lets you create control add-ins that can display and update data in the database. Data binding is accomplished through Microsoft Dynamics NAV Server with the SourceExpr Property of the field control that is applied with the control add-in, as shown in the following illustration.

RoleTailored client control add-in data binding

The control add-in must implement the Microsoft.Dynamics.Framework.UI.Extensibility.IValueControlAddInDefinition interface that exposes the IValueControlAddInDefinition.Value property as shown in the following example for a DateTime data type.

[ControlAddInExport("MyControlAddIn")]  
public class MyControlAddIn : IValueControlAddInDefinition<DateTime>  
{  
    ...  
}  

When a control add-in is instantiated on a page, the SourceExpr property value is passed to the control add-in IValueControlAddInDefinition.Value property. The SourceExpr property can be a field or row in a database table or a C/AL global variable.

Note

The SourceExpr property value can be passed to the IValueControlAddInDefinition.Value property multiple times as long as a page is open, depending on application code or state in the Microsoft Dynamics NAV Windows client.

For more information about how to implement the Microsoft.Dynamics.Framework.UI.Extensibility.IValueControlAddInDefinition interface, see How to: Create a Windows Client Control Add-in.

For more information about how to set the SourceExpr property for a control add-in, see How to: Set Up a Windows Client Control Add-in on a Page.

Supported Data Types

A control add-in can bind with several data types from the database. Each data type in C/AL maps to a corresponding .NET Framework data type in the control add-in as listed in the following table.

C/AL data type Control add-in data type
BigInteger [Int64]
BigText [String]
BLOB [Object]
Boolean [Boolean]
Byte [Byte]
Char [Char]
Code [System.String]
Date [DateTime]
DateFormula [String]
DateTime [DateTime]
Decimal [Decimal]
Duration [TimeSpan]
Guid [Guid]
Integer [Int32]
Option [Int32]
RecordID [String]
Text [String]
Time [DateTime]

Data Mapping and Multiple Data Types

The mapping between the C/AL data type of the page control and the .NET Framework data type occurs when the control add-in is instantiated on a page in the Microsoft Dynamics NAV Windows client. For example, if a page contains a control that uses a Date data type in C/AL and the control add-in implements the Boolean data type (IValueControlAddInDefinition<Boolean>), then an error occurs.

A control add-in can support multiple .NET Framework data types by implementing the Microsoft.Dynamics.Framework.UI.Extensibility.IValueControlAddInDefinition interface for each data type. For example, to support both a string and an integer data type, include the following code.

public class MyControlAddIn : IValueControlAddInDefinition<String>, IValueControlAddInDefinition<Int32>  

See Also

Developing Windows Client Control Add-ins
Client Extensibility API Overview
How to: Create a Windows Client Control Add-in
Exposing Events and Calling Respective C/AL Triggers from a Windows Client Control Add-in
Installing and Configuring Windows Client Control Add-ins on Pages
Windows Client Control Add-in Overview