cancel
Showing results for 
Search instead for 
Did you mean: 

Fill matrix with user defined text

Former Member
0 Kudos

Hi all,

i've created a form with a matrix on it (with screenpainter). Now i'd like to fill the matrix with user defined data which is not bound to a table.

Is there any way to do this?

Here's my code (The form with the matrix appears, but

the matrix is not filled):

Dim oMatrix As SAPbouiCOM.Matrix

Dim oColumns As SAPbouiCOM.Columns

Dim oColumn As SAPbouiCOM.Column

Dim oCell As SAPbouiCOM.Cell

LoadFromXML (App.Path & "\anrufen.srf")

Set oForm = objSBOApp.Forms.Item("30000")

Set oMatrix = oForm.Items("matrix").Specific

Set oColumns = oMatrix.Columns

Set objColumn = oMatrix.Columns("Col1")

oMatrix.AddRow

Set oCell = objColumn.Cells(1)

oCell.Specific.String = "Hello"

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you Lutz,

that's what i thought --> The matrix "must" be bound to a datasource.

Thanks Gerhard

Former Member
0 Kudos

Gerhard,

in order to fill a matrix with data, you need to bind the columns to datasources.

The following example is also available for download via SAP Business One Main page.

HTH Lutz Morrien

<code>

'// SAP MANAGE UI API 6.5 SDK Sample

'//****************************************************************************

'//

'// File: MatrixAndDataSources.cls

'//

'// Copyright (c) SAP MANAGE

'//

'// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF

'// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO

'// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A

'// PARTICULAR PURPOSE.

'//

'//****************************************************************************

'//**************************************************************************************************

'// BEFORE STARTING:

'// 1. Add reference to the "SAP Business One UI API"

'// 2. Insert the development connection string to the "Command Line Argument"

'//----


'// 1.

'// a. Project->References

'// b. check the "SAP Business One UI API" check box

'//

'// 2.

'// a. Project->Properties

'// b. choose 'Make' tab folder

'// c. place the following connection string in the 'Command Line Arguments' field

'// 0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056

'//

'//**************************************************************************************************

Option Explicit

'//**********************************************************

'// This parameter will use us to manipulate the

'// SAP Business One Application

'//**********************************************************

Private WithEvents SBO_Application As SAPbouiCOM.Application

Private oForm As SAPbouiCOM.Form

Private Sub SetApplication()

'*******************************************************************

'// Use an SboGuiApi object to establish connection

'// with the SAP Business One application and return an

'// initialized appliction object

'*******************************************************************

Dim SboGuiApi As SAPbouiCOM.SboGuiApi

Dim sConnectionString As String

Set SboGuiApi = New SAPbouiCOM.SboGuiApi

'// by following the steped specified above the following

'// statment should be suficient for either development or run mode

sConnectionString = Command

'// connect to a running SBO Application

SboGuiApi.Connect sConnectionString

'// get an initialized application object

Set SBO_Application = SboGuiApi.GetApplication()

End Sub

Private Sub CreateFormWithMatrix()

'//*******************************************************

'// Don't Forget:

'// it is much more efficient to load a form from xml.

'// use code only to create your form.

'// once you have created it save it as XML.

'// see "WorkingWithXML" sample project

'//*******************************************************

Dim oItem As SAPbouiCOM.Item

'// *******************************************

'// we will use the following objects to set

'// the specific values of every item

'// we add.

'// this is the best way to do so

'//*********************************************

Dim oButton As SAPbouiCOM.Button

Dim oMatrix As SAPbouiCOM.Matrix

Dim oColumns As SAPbouiCOM.Columns

Dim oColumn As SAPbouiCOM.Column

'// add a new form

Set oForm = SBO_Application.Forms.Add("MatrixForm")

'// set the form properties

oForm.Title = "Matrix Form"

oForm.Left = 336

oForm.Width = 576

oForm.Top = 44

oForm.Height = 325

'//*****************************************

'// Adding Items to the form

'// and setting their properties

'//*****************************************

'/**********************

'// Adding an Ok button

'//*********************

'// We get automatic event handling for

'// the Ok and Cancel Buttons by setting

'// their UIDs to 1 and 2 respectively

Set oItem = oForm.Items.Add("1", it_BUTTON)

oItem.Left = 5

oItem.Width = 65

oItem.Top = 273

oItem.Height = 19

Set oButton = oItem.Specific

oButton.Caption = "Ok"

'//************************

'// Adding a Cancel button

'//***********************

Set oItem = oForm.Items.Add("2", it_BUTTON)

oItem.Left = 75

oItem.Width = 65

oItem.Top = 273

oItem.Height = 19

Set oButton = oItem.Specific

oButton.Caption = "Cancel"

'//***************************

'// Adding a Matrix item

'//***************************

Set oItem = oForm.Items.Add("Matrix1", it_MATRIX)

oItem.Left = 5

oItem.Width = 557

oItem.Top = 5

oItem.Height = 260

Set oMatrix = oItem.Specific

Set oColumns = oMatrix.Columns

'//***********************************

'// Adding Culomn items to the matrix

'//***********************************

Set oColumn = oColumns.Add("#", it_EDIT)

oColumn.TitleObject.Caption = "#"

oColumn.Width = 30

oColumn.Editable = False

Set oColumn = oColumns.Add("UserName", it_EDIT)

oColumn.TitleObject.Caption = "User Name"

oColumn.Width = 127

oColumn.Editable = True

Set oColumn = oColumns.Add("UserEmail", it_EDIT)

oColumn.TitleObject.Caption = "E-Mail"

oColumn.Width = 127

oColumn.Editable = True

Set oColumn = oColumns.Add("UserPhone", it_EDIT)

oColumn.TitleObject.Caption = "Phone Number"

oColumn.Width = 127

oColumn.Editable = True

Set oColumn = oColumns.Add("Remarks", it_EDIT)

oColumn.TitleObject.Caption = "Remarks"

oColumn.Width = 127

oColumn.Editable = True

End Sub

Public Sub AddDataSourceToForm()

'//****************************************************************

'// every item must be binded to a Data Source

'// prior of binding the data we must add Data sources to the form

'//****************************************************************

'// Add a DBDataSource to Users table

oForm.DataSources.DBDataSources.Add ("OUSR")

'// Add a user data source

oForm.DataSources.UserDataSources.Add "Remarks", dt_LONG_TEXT, 30

'// you may add many data sources

End Sub

Public Sub BindDataToForm()

'//********************************************************

'// binding data to the Form items will set the connection

'// between the requested DB table field and the item

'//********************************************************

Dim oMatrix As SAPbouiCOM.Matrix

Dim oColumns As SAPbouiCOM.Columns

Dim oColumn As SAPbouiCOM.Column

'// getting the form's matrix object

Set oMatrix = oForm.Items.Item("Matrix1").Specific

Set oColumns = oMatrix.Columns

'// getting the matrix columns by the UID

Set oColumn = oColumns.Item("UserName")

'// bindidng the data

oColumn.DataBind.SetBound True, "OUSR", "U_NAME"

Set oColumn = oColumns.Item("UserEmail")

oColumn.DataBind.SetBound True, "OUSR", "E_Mail"

Set oColumn = oColumns.Item("UserPhone")

oColumn.DataBind.SetBound True, "OUSR", "PortNum"

Set oColumn = oColumns.Item("Remarks")

'//************************************************

'// to Data Bind an item with a user Data source

'// the table name value should be an empty string

'//************************************************

oColumn.DataBind.SetBound True, "", "Remarks"

End Sub

Public Sub GetDataFromDataSourec()

Dim oDBDataSource As SAPbouiCOM.DBDataSource

Dim oUserDataSource As SAPbouiCOM.UserDataSource

Dim oMatrix As SAPbouiCOM.Matrix

Dim i As Long '// to be used as counter

'// getting the data sources from the form

Set oDBDataSource = oForm.DataSources.DBDataSources.Item("OUSR")

Set oUserDataSource = oForm.DataSources.UserDataSources.Item("Remarks")

'// getting the matrix from the form

Set oMatrix = oForm.Items.Item("Matrix1").Specific

oMatrix.Clear

'// Querying the DB Data source

oDBDataSource.Query

'// setting the user data source data

oUserDataSource.Value = "Your remarks here ..."

For i = 0 To oDBDataSource.Size - 1

oDBDataSource.Offset = i

oMatrix.AddRow

Next i

oMatrix.AutoResizeColumns

End Sub

Private Sub Class_Initialize()

'//*************************************************************

'// set SBO_Application with an initialized application object

'//*************************************************************

SetApplication

'//*************************************************************

'// Create a simple Form with matrix

'// Don't forget: once you've created the form

'// save it as an XML and load it from XML the next

'// time you wish to use this form

'//*************************************************************

CreateFormWithMatrix

'// Add Data Sources to the Form

AddDataSourceToForm

'// Bind the Form's items with the desired data source

BindDataToForm

'// Fill the matrix with data

GetDataFromDataSourec

'// Show my Simple Form

oForm.Visible = True

End Sub

</code>