Change color of a matrix row
Emanuele Croci
Dear all,how can I change the background color of a matrix row or matrix cell?
Best regards
Emanuele
Lorenz Stierlin
Hi EmanuelePlease try following code snippet:
//SAP object
SAPbouiCOM.Form oSAPForm = SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.ActiveForm;
SAPbouiCOM.Item oItem = oSAPForm.Items.Item("38");
SAPbouiCOM.Matrix oMatrix = (SAPbouiCOM.Matrix) oItem.Specific;
//Set cell background
oMatrix.CommonSetting.SetCellBackColor(3, 3, 135);
//Set row background
oMatrix.CommonSetting.SetRowBackColor(3, 135);
//Form updating
oSAPForm.Update();
Kind Regards,
Lorenz
Emanuele Croci
Dear Lorenz,thank you for your help.
' HERE A NEED TO CHANGE THE COLOR OF THIS SPECIFIC ROW
' BUT I HAVE AN ERROR: CommonSetting is not a method of matrix
This is my source code of optimizer function:
Try
Dim matrix As customize.UI.Components.Matrix = customize.UI.Components.Matrix.GetFromUID(pval.Form, "3")
For i As Integer = 0 To matrix.Rows.Count - 1
' extract the TransId
Dim transId As String = CStr(matrix.GetValue("4", i))
Dim transType As String = CStr(matrix.GetValue("7", i))
If (transType = "PE" Or transType = "PU") And transId <> "" Then
Dim query As String
query = "SELECT count(*) As ContaRigheSconti " & _
" FROM JDT1 T1 " & _
" WHERE T1.TransId = " & transID & _
" AND T1.ShortName in ('60200', '60300') "
Dim cmd As System.Data.SqlClient.SqlCommand
cmd = New System.Data.SqlClient.SqlCommand(query)
'execute query
Using sdr As System.Data.SqlClient.SqlDataReader = customize.B1Connector.GetB1Connector().ExecuteQuery(cmd)
If sdr.Read() Then
If sdr(0) > 0 Then
' HERE A NEED TO CHANGE THE COLOR OF THE ROW
' BUT I HAVE AN ERROR: CommonSetting is not a method of matrix
'matrix.CommonSetting.SetRowBackColor(3, 135)
pVal.Form.Update()
End If
End If
End Using
End If
Next
Return True
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "")
customize.Messaging.Debug.DebugLevel.Exception)
End Try
Return True
Alternatively, I could add a new column in the matrix where I can write a specific string when my condition is satisfied...
Best regards
Emanuele
Emanuele Croci
Dear Lorentz,I solved my problem using the SAPbouiCOM objects instead of customize components to change the color of a specific row.
[size=2]Try[/size]
Dim matrix As customize.UI.Components.Matrix = customize.UI.Components.Matrix.GetFromUID(pval.Form, "3")
For i As Integer = 0 To matrix.Rows.Count - 1
[size=2] Dim transId As String = CStr(matrix.GetValue("4", i))[/size]
Dim transType As String = CStr(matrix.GetValue("7", i))
If (transType = "PE" Or transType = "PU") And transId <> "" Then
Dim query As String
query = "SELECT count(*) As ContaRigheSconti " & _
" FROM JDT1 T1 " & _
" WHERE T1.TransId = " & transID & _
" AND T1.ShortName in ('60200', '60300') "
Dim cmd As System.Data.SqlClient.SqlCommand
cmd = New System.Data.SqlClient.SqlCommand(query)
'execute query
Using sdr As System.Data.SqlClient.SqlDataReader = customize.B1Connector.GetB1Connector().ExecuteQuery(cmd)
If sdr.Read() Then
If sdr(0) > 0 Then
' change color to RED for this matrix row
Dim oSAPForm As SAPbouiCOM.Form = SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.ActiveForm
Dim oItem As SAPbouiCOM.Item = oSAPForm.Items.Item("3")
Dim oMatrix As SAPbouiCOM.Matrix = oItem.Specific
[size=2]'oMatrix.CommonSetting.SetCellBackColor(i+1, 2, 250)[/size]
'oMatrix.CommonSetting.SetCellBackColor(i+1, 4, 250)
'oMatrix.CommonSetting.SetCellBackColor(i+1, 7, 250)
[size=2]oMatrix.CommonSetting.SetRowBackColor(i[/size]+1[size=2], 250)[/size]
End If ' sdr(0) > 0
End If ' sdr.Read()
End Using ' sdr
End If ' (transType = "PE" Or transType = "PU") And transId <> ""
Next ' For i As Integer = 0 To matrix.Rows.Count - 1
Return True
Catch ex As Exception
MessageBox.Show("Errore: " & ex.Message, "")
[size=2]End Try[/size]
Return True
Thank you for your help.
Best regards
Emanuele
Emanuele Croci
Dear Lorenz,just another question...
How can I add a new column in the matrix?
This code gives me an error: Matrix - Line Exists
Try
Dim oSAPForm2 As SAPbouiCOM.Form = SwissAddonFramework.B1Connector.GetB1Connector().Application.Forms.ActiveForm
Dim oMatrixNew As SAPbouiCOM.Matrix = oSAPForm2.Items.Item("3").Specific
oMatrixNew.Columns.Add("discnew", SAPbouiCOM.BoFormItemTypes.it_EDIT)
Catch ex1 As Exception
MessageBox.Show("Error: " & ex1.Message, "")
End Try
Best regards
Emanuele
0
Please sign in to leave a comment.
Comments
0 comments