Data Grid code

In this example we show how to work with a Data Grid control in the code-behind and how to map a Data Grid to XML schema to produce a proper (non-flat) XML form data.

To prepare the test eForm follow these steps:

1. Create a new project or open an existing one and add a new form.

2. Put a Code Block component named NDCode1 on the form.

3. Add a Data Grid control to the form and leave its default name NDDataGrid1.

4. Add three columns to the data grid NDDataGrid1 (open the collection editor of the data grid’s property Columns of in the Properties panel (see next screenshot).

 Picture – Example 5 – Collection editor

 

5. Add following three items to the Columns collection of the DataGrid: a DataGridTextColumn, a DataGridComboBoxColumn and a DataGridCheckBoxColumn.

a) Select the first (text) column, than set its property SortMemberPath to TextColumn1, property Header to “Text Column” and property IsReadOnly to true by checking the property’s check box.
b) Select the second (combo box) column and modify values of its properties: SortMemberPath to

6. Drop nine buttons on the form and do the following changes on them:

a) Select the first button (named Button1), rename it to BtnAdd and set its content (the value of the button’s Content property) to text “Add Row” (without the quotation marks).
b) Select the second button (Button2), rename it to BtnDel and set its content to “Delete Rows”.
c) Rename the third button (Button3) to BtnSetText and set its content to “Set Text”.
d) Rename the fourth button (Button4) to BtnSetCombo and set the content of the button to “Set Combo”.
e) Rename the fifth button (Button5) to BtnSetCheck and change its content to “Set Check”.
f) Set the name of the sixth button (Button6) to BtnClearAll and set the property Content of the button to “Clear Rows”.
g) Change the name of the seventh button (Button7) to BtnClearText and change the value of the Content property to “Clear Combo”.
h) Set content of the eighth button to “Clear Combo” and its name to BtnClearCombo.
i) Change Content property of the ninth button (Button9) to “Clear Check” and set its name to BtnClearCheck.

 Picture – Example 5 – DataGrid Events and Code