| S2Container.NET TOP page # S2Form .NET Framework 2.0 and Above What is S2Form? How To Create Windows Form that extends S2Form How To Create Controls How To Create PONO Class Setting and getting PONO Object Grid Control ## What is S2Form? S2Form is the WindowsForm that binds Automatically the PONO(Plain Old .NET Object) object. When Set the PONO object to DataSource property, S2Form Binds that to the controls on the form. S2Form Updates the object's value if input to control. And、Using DataSource property, S2Form provides updated value of control through the PONO object. ## How To Create Windows Form that extends S2Form To Use S2Form, Create WindowsForm that extends Seasar.Windows.S2Form. Create as below on Visual Studio 2005 Select "Extended Form" from "New Item". Next, Select the parent form. On next picture, Click "refer" Button. Select the Seasar.Windows.Dll. Next, Click "OK" button, selecting S2Form. ## How To Create Controls Ordinally, Create Controls On the created windowsform. Use ControlModifierAttribute when adding modifier before name, or to use Hungrian Nameing Rule, etc. ControlModifier have two arguments. First argument means prefix. Second means surfix. C#
    [ControlModifier("txt", "")]
    public partial class FrmEmployeeList : S2Form
    {
     ...
    }
VB.NET
    <ControlModifier("txt", "")> _
    Public Class FrmEmployeeList
     ...
    End Class
Default controls's property to bind is "Text" 。Use Control Attribute using control that have no "Text" property.
Name | Description
--- | ---
Control(controlName, controlProperty, propertyName) | controlName means target control's name. controlProperty means target control's property. propertyName meas PONO object's property name.
Control(controlName, controlProperty, propertyName, updateMode) | controlName means target control's name. controlProperty means target control's property. propertyName meas PONO object's property name. updateMode means the updated timing.
Control(controlName, controlProperty, propertyName, formattingEnabled, updateMode, nullValue, formatString) | controlName means target control's name. controlProperty means target control's property. propertyName meas PONO object's property name. formattingEnabled is true when setting formatString. updateMode means the updated timing. nullValue set to control when PONO value is DBNull. formatString means the format string.
ControlAttribute has priority over the PONO property on binding to controls. C#
    [ControlModifier("txt", "")]
    [Control("lblName", "Text", "Name")]
    public partial class FrmEmployeeList : S2Form
    {
     ...
    }
VB.NET
    <ControlModifier("txt", "")> _
    <Control("lblName", "Text", "Name")> _
    Public Class FrmEmployeeList
     ...
    End Class
The default reflection timing from control to the PONO object is DataSourceUpdateMode#OnValidation. Control's value will reflects immidately to object as below. C#
    [ControlModifier("txt", "")]
    [Control("lblName", "Text", "Name", DataSourceUpdateMode.OnPropertyChanged)]
    public partial class FrmEmployeeList : S2Form
    {
     ...
    }
VB.NET
    <ControlModifier("txt", "")> _
    <Control("lblName", "Text", "Name", DataSourceUpdateMode.OnPropertyChanged)> _
    Public Class FrmEmployeeList
     ...
    End Class
## How To Create PONO Class Create the PONO class the same name properties as form's controls. ## Setting and getting PONO Object Use DataSource property of S2Form. Setting PONO： C#:
    EmployeeListDto data = _service.GetAll();
    this.DataSource = data;
VB.NET
    Dim data As EmployeeListDto = _service.GetAll();
    Me.DataSource = data;
Getting PONO： C#:
    EmployeeListDto data = (EmployeeListDto)this.DataSource;
VB.NET:
    Dim data As EmployeeListDto = CType(Me.DataSource, EmployeeListDto)
## Reflect to controls from changing value of the binding object. There are two ways. First way is binding the object again. Second, after change the value of binding objct, execute S2Form#Readvalues.
    [ControlModifier("txt", "")]
    [Control("lblName", "Text", "Name")]
    [Control("sprList", "DataSource", "List")]
    public partial class FrmEmployeeList : S2Form
    {
     ...
    }
S2Form has WriteValues method to reflect to the binding object from controls by force. This method is not need usually. ## Grid-typed Control Now, We check DataGridView And SPREAD 2.5J Control. To bind object to Grid-typed control, PONO has property that is IList, Generics.IList, Array, DataTable, IEnumurable, and Generics.IEnumurable type. This property binds to control using Control Attribute. Grid-typed control uses generally DataSource property to bind. Grid-typed control is set separately collection property inclued PONO object. This auto-binding is not functioned. Changing row size happens at some grid-type control. And, generating columns happens at some grid-type control. Adding Row Binding data prevents using the method of grid control to add row. So, Insert data to the control by S2Form#AddRow.
Name | Description
--- | ---
AddRow(propertyName, data, row) | propertyName means target PONO object's property name. data means the inserted data. row means the inserted row number Returned value is inserted row's count.
Deleting row As insertion of row, binding data prevents deleting row by using grid control's method. So, Insert data to the control by S2Form#DeleteRow. if delete multiple rows, use S2Form#DeleteRows.
Name | Description
--- | ---
DeleteRow(propertyName, row) | propertyName means target PONO object's property name. row means Deleting row number. Returned value is delete row's count.
DeleteRows(propertyName, startRow, endRow) | propertyName means target PONO object's property name. startRow means deleting start row number. endRow means deleting end row number. Returned value is delete row's count.
Moving row Binding data prevents moving row using control's method.So, Use S2Form#MoveUpRow to move up one row. To move down one row, S2Form#MoveDownRow.
Name | Description
--- | ---
MoveUpRow(propertyName, row) | propertyName means target PONO object's property name. row means moving row number 。
MoveDownRow(propertyName, row) | propertyName means target PONO object's property name. row means moving row number 。
Trans. by H.Fujii | Copyright© 2004-2007, The Seasar Foundation and the others. All rights reserved.