.NET Example: Parameters Not Fully Converted

About this task

Because there are endless .NET event argument types, the common and most useful types will be converted first for the .NET Component Host; additional .NET argument types will be converted in future CIMPLICITY releases.

However, when parameters are not fully converted, the controls can be configured using CimEdit features, such as events, scripts and procedures.

A DataGrid and ComboBox, which are available in the .NET Component Browser, have properties of not fully converted data types that have these requirements.

Note: The DataGrid and ComboBox example:
  • Will be configured to display logged data in the DataGrid whose category can be selected in the ComboBox.
  • Uses the Microsoft SQL Server sample database Northwind.mdf/Mothwind.ldf files, which can be downloaded from the Microsoft Website.
Important: Before you work with or apply this example make sure that a Virtual integer point is available for the script.

The sample uses a point named SEL_INDEX.

  • Controls: Script - Part 1
  • Controls: Script - Part 2

Controls: Script - Part 1

Once a chart is placed on the screen, scripting can be started that will pull data into the control from SQL Server.

1 Controls: Place and resize on the CimEdit screen.
2 Controls: Create a new script.
3 Controls: Test the script - Part 1.
  1. Controls: Place and Resize on the CimEdit Screen

DataGrid: Place on the CimEdit screen.

Procedure

  1. Open the .NET Components Browser.
  2. Select .NET Components>.NET Framework>Windows Presentation Framework>Presentation Framework>DataGrid.
  3. Close the .NET Components Browser.
  4. Resize the DataGrid.

    Note: Since the DataGrid runtime representation is blank, approximate its size. You can modify the size later.

  5. Open the DataGrid's Properties - Object dialog box.
  6. Select General.
  7. Name the DataGrid in the Object name field (e.g. Data Grid1).
  8. Close the Properties - Object dialog box.

    ComboBox: Place and Resize on the CimEdit screen.

  9. Open the .NET Components Browser.
  10. Select .NET Components>.NET Framework>Windows Presentation Framework>Presentation Framework>ComboBox.
  11. Close the .NET Components Browser.
  12. Resize the ComboBox.

    Since the ComboBox runtime representation displays a drop list arrow aiding you to approximate its size. You can modify the size later.

  13. Open the ComboBox's Properties - Object dialog box.
  14. Select General.
  15. Name the ComboBox in the Object name field (e.g. Combo Box1).
  16. Close the Properties - Object dialog box.

    The controls

    Note: Colors and fonts that are different from the default colors and fonts can be selected at anytime in the control's Properties - Object dialog box>Control Properties list.

    Solid colors can be selected for the DataGrid rows.

    Example

    The following colors are selected for the DataGrid rows.

    Row RGB Color
    AlternatingRowBackground_Color1 218,227,188
    RowBackground_Color1 250,192,143

    The DataGrid rows will alternate these colors during runtime.

    1. Controls: Create a New Script

    Scripts that will populate the DataGrid and ComboBox are based on a Screen Open event.

    • DataGrid: Create a Script  - Part 1
    • ComboBox: Create a Script - Part 1

    DataGrid: Create a Script - Part 1

    1. Add a Screen Open event to the DataGrid control.
    2. Create a new script.
    3. Add the following code to the script.

    Important: Change the information, if necessary, to match your database specifications.

    Private cimOleObj As Occ_PresentationFramework.IOccDataGrid
    Sub OnScreenOpen()
        Dim conn As Object
        Dim rs As Object
        
        Set conn = CreateObject("ADODB.Connection")
        Set rs = CreateObject("ADODB.Recordset")   
        conn.ConnectionString = "Provider=SQLNCLI10;Data Source=.\sqlexpress;" _
            & "AttachDbFilename=C:\SQLSampleDatabases\NORTHWND.MDF;Integrated Security=SSPI;"
        
        conn.Open    
        rs.Open "Select Top 20 * from Orders", conn
        Set cimOleObj.ItemsSource = rs
        
        rs.Close
        conn.Close
    End Sub
    1. Compile the script; close the Edit Script window.
    2. Close the DataGrid's Properties - Object dialog box.

    ComboBox: Create a Script - Part 1

    1. Add a Screen Open event to the ComboBox control
    2. Create a new script.
    3. Add the following code to the script.

    Important: Change the information, if necessary, to match your database specifications.

    Private cimOleObj As Occ_PresentationFramework.IOccComboBox
    Sub OnScreenOpen()
        Dim conn As Object
        Dim rs As Object
        
        Set conn = CreateObject("ADODB.Connection")
        Set rs = CreateObject("ADODB.Recordset")   
        conn.ConnectionString = "Provider=SQLNCLI10;Data Source=.\sqlexpress;" _
            & "AttachDbFilename=C:\SQLSampleDatabases\NORTHWND.MDF;Integrated Security=SSPI;"
        
        conn.Open    
        rs.Open "Select Top 20 * from Orders", conn
        
        Do While Not rs.EOF
            cimOleObj.Items.Add CStr(rs("CustomerID"))
            rs.MoveNext
        Loop
        cimOleObj.SelectedIndex = 0
        
        rs.Close
        conn.Close
    End Sub
    1. Compile the script; close the Edit Script window.
    2. Close the ComboBox's Properties - Object dialog box.
    1. Controls: Test the Script - Part 1

    The controls should now display data from the selected database (e.g. Northwind).

    A user can:

    A Scroll up and down the DataGrid to review data.
    B Select different items on the ComboBox drop down list.

    There is currently no connection between the DataGrid and the ComboBox.

    Controls: Script - Part 2

    When two additional scripts are applied to a procedure, they will connect the two .NET controls and cause the ComboBox selection to drive the DataGrid display.

    1 Controls: Add subroutines- Part 2
    2 Controls: Create a procedure to invoke the scripts.
    3 Controls: Test scripts and procedures.
    1. Controls: Add Subroutines - Part 2

    The .NET controls subroutines get and set the Virtual point that you created or selected for use before placing the controls on the CimEdit screen.

    ComboBox: Add a Subroutine

    A ComboBox subroutine sets the point (e.g. SEL_INDEX).

    This is the companion to the DataGrid subroutine that will get the point.

    Sub GetSelection()
    PointSet "SEL_INDEX", cimOleObj.SelectedIndex
    End Sub

    DataGrid: Add a Subroutine

    A DataGrid subroutine gets the point (e.g. SEL_INDEX).

    This is the companion to the ComboBox subroutine that will set the point.

    Sub SetSelection()
    cimOleObj.SelectedIndex = PointGet("SEL_INDEX")
    End Sub
    1. Controls: Create a Procedure to Invoke the Scripts
    Note:

    Because the two parameters are of the COM Variant type, it's not as straightforward to use a handler routine as, for example, Mouse events.

    However, because both the DataGrid and ComboBox each have the SelectionIndex property, the selection in the ComboBox drop down list can be determined and the corresponding row selection of the DataGrid component can be set by accessing their SelectionIndex properties.

    A straightforward way to configure the parameters is through an ActiveX Event>SelectionChanged event and a procedure that uses InvokeScript actions.

    • ComboBox: Configure SetChangedProc
    • DataGrid: Configure SetChangedProc

    ComboBox: Configure SetChangedProc

    1. Open the ComboBox Properties - Object dialog box.
    2. Select Events.
    3. Create an ActiveX Event>SelectionChanged event.
    4. Create a new procedure for the event.

    The procedure Includes two Invoke script actions.

    1 Procedure name Name to clearly identify the procedure. Example SetChangedProc
    2 Action type 1 Invoke script
    3 Object name1 Select the name that was entered in the ComboBox's Properties - Object dialog box>General>Object name field. Example Combo Box1
    4 Method1 GetSelection
    2 Action type 2 Invoke script
    3 Object name2 Select the name that was entered in the DataGrid's Properties - Object dialog box>General>Object name field Example DataGrid1
    4 Method SetSelection
    1. Click Apply; close the ComboBox control's Properties - Object dialog box.

    DataGrid: Configure SetChangedProc

    Configure the same ActiveX Event>Selection Changed event with the same SetChangedProc in the DataGrid control's Properties - Object dialog box.

    1. Controls: Test Scripts and Procedures -

    If the scripts and configuration are completed correctly the DataGrid control now automatically highlights the data row based on the selection made in the ComboBox control.