# Binding InputPanel with DataTable

## Content

**InputPanel** supports data binding through data tables. You can create a data table using the standard **DataTable** class and bind it to the InputPanel control by setting the [ItemsSource](/componentone/api/wpf/online-inputpanel/dotnet-framework-api/C1.WPF.InputPanel.4.6.2/C1.WPF.InputPanel.C1InputPanel.ItemsSource.html) property.

Complete the following steps to bind InputPanel to data through data table.

1. [Set up the application](/componentone/docs/wpf/online-inputpanel/DataBinding/Binding-InputPanel-with-DataTable#set-up-the-application)
2. [Create a data table to bind with InputPanel](/componentone/docs/wpf/online-inputpanel/DataBinding/Binding-InputPanel-with-DataTable#create-a-data-table-to-bind-with-inputpanel)
3. [Bind the data table to InputPanel](/componentone/docs/wpf/online-inputpanel/DataBinding/Binding-InputPanel-with-DataTable#bind-the-data-table-to-inputpanel)

### Set up the application

1. Create a WPF application.
2. Add the InputPanel control and name it InPanel.

### Create a data table to bind with InputPanel

1. Add a new class, **Employee**, to the application.
2. Add the following import statement. 

    ```vbnet
    Imports System.Data
    ```

    ```csharp
    using System.Data;
    ```
3. Create an object, employee, of **DataTable** class.

    ```vbnet
    'Create a data table
    Private _employees As DataTable = Nothing
    ```

    ```csharp
    //Create a data table
    private DataTable employees = null;
    ```
4. Add data fields to be added in the table.

    ```vbnet
    'Add data fields 
    Shared _rnd As New Random()
    Shared _firstNames As String() = "Andy|Ben|Charlie|Dan|Ed|Fred|Gil".Split("|"c)
    Shared _lastNames As String() = "Ambers|Bishop|Cole|Danson|Evers|Trask|Ulam".Split("|"c)
    Shared _countries As String() = "China|India|United States|Japan|Myanmar".Split("|"c)
    ```

    ```csharp
    //Add data fields 
    static Random _rnd = new Random();
    static string[] _firstNames = "Andy|Ben|Charlie|Dan|Ed|Fred|Gil".Split('|');
    static string[] _lastNames = "Ambers|Bishop|Cole|Danson|Evers|Trask|Ulam".Split('|');
    static string[] _countries = "China|India|United States|Japan|Myanmar".Split('|');
    ```
5. Add class definition to assign fields to the data table.

    ```vbnet
    'Initialize data table
    Public ReadOnly Property Employees() As DataTable
        Get
            If _employees Is Nothing Then
                _employees = New DataTable("Employees")
                _employees.Columns.Add("ID", System.Type.[GetType]("System.String"))
                _employees.Columns.Add("FirstName", System.Type.[GetType]("System.String"))
                _employees.Columns.Add("LastName", System.Type.[GetType]("System.String"))
                _employees.Columns.Add("Countries", System.Type.[GetType]("System.String"))
                _employees.Columns.Add("BirthDate", System.Type.[GetType]("System.DateTime"))
                For row As Integer = 0 To 9
                    Dim dRow As DataRow = _employees.NewRow()
                    dRow("ID") = _rnd.[Next](100000, 999999).ToString()
                    dRow("FirstName") = _firstNames(_rnd.[Next](_firstNames.Length))
                    dRow("LastName") = _lastNames(_rnd.[Next](_lastNames.Length))
                    dRow("Countries") = _countries(_rnd.[Next](_countries.Length))
                    dRow("BirthDate") =
                        DateTime.Today.AddDays(-_rnd.[Next](1, 365))
                    _employees.Rows.Add(dRow)
                Next
            End If
            Return _employees
        End Get
    End Property
    ```

    ```csharp
    //Initialize data table
    public DataTable Employees
    {
        get
        {
            if (employees == null)
            {
                employees = new DataTable("Employees");
                employees.Columns.Add("ID", 
                    System.Type.GetType("System.String"));
                employees.Columns.Add("FirstName", 
                    System.Type.GetType("System.String"));
                employees.Columns.Add("LastName", 
                    System.Type.GetType("System.String"));
                employees.Columns.Add("Countries", 
                    System.Type.GetType("System.String"));
                employees.Columns.Add("BirthDate", 
                    System.Type.GetType("System.DateTime"));
                for (int row = 0; row < 10; row++)
                {
                    DataRow dRow = employees.NewRow();
                    dRow["ID"] = _rnd.Next(100000, 999999).ToString();
                    dRow["FirstName"] = _firstNames[_rnd.Next(_firstNames.Length)];
                    dRow["LastName"] = _lastNames[_rnd.Next(_lastNames.Length)];
                    dRow["Countries"] = _countries[_rnd.Next(_countries.Length)]; ;
                    dRow["BirthDate"] = DateTime.Today.AddDays(-_rnd.Next(1, 365));
                    employees.Rows.Add(dRow);
                }
            }
            return employees;
        }
    }
    ```

### Bind the data table to InputPanel

1. Set the **ItemsSource** property in XAML view to bind InputPanel with the data table.

    ```xml
    <c1:C1InputPanel Name="InPanel" ItemsSource="{Binding Employees}"/>
    ```
2. Switch to the **MainWindow.xaml.cs** file and set the **DataContext** property. 

    ```vbnet
    'Set data context
    Me.DataContext = New EmployeeDataContext()
    ```

    ```csharp
    //Set data context
    this.DataContext = new Employee();
    ```