on 12-04-2014 9:31 AM
Hi,
For learning purposes, I am working on the sample which comes with SDK called: 19.Grid.
I have modified the basic sample as follows:
The relevant code I used is shown at the bottom of this thread.
oGrid.CommonSetting.SetRowBackColor(pVal.Row + 1, newColor)
When I group on Card Code and Expand all rows, the code for background color works fine:
When I tick any checkbox, the row becomes blue.
When I untick the checkbox, the row returns to gray.
No problem at all here..
------------------------------------------
Problem:
Problems arise when some rows are collapsed.
The attached picture explains the problem better than words.
It seems that when there are collapsed rows ABOVE the relevant checkbox, then pVal.Row is not working properly.
If I expand all rows, the rows are correctly colored when I tick a checkbox.
--------------------------------------
Request:
Anybody knows what is happening, and propose a solution?
Thanks
Leon Lai
------------------------------------------------
Picture:
--------------------------------------------------------
Relevant Code: (in SBO_Application > ItemEvent)
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
BubbleEvent = True
Dim EventEnum As SAPbouiCOM.BoEventTypes
EventEnum = pVal.EventType
If (FormUID = "frmGrid") And ((pVal.ItemUID = "optNo") Or _
(pVal.ItemUID = "optCode")) And _
(pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED) And (pVal.BeforeAction = False) Then
If (userDS.Value = 1) Then
oForm.Freeze(True)
DocStatus, U_HandOver, ShipToCode from OINV where U_HandOver IS NULL and ShipToCode NOT LIKE '%Address' ")
oForm.DataSources.DataTables.Item(0).ExecuteQuery("Select TOP 3000 CardCode, CardName, DocDate, DocEntry, DocNum, DocTotal, DocStatus, U_HandOver, ShipToCode from OINV where U_HandOver IS NULL ")
oGrid.Columns.Item("U_HandOver").Type = SAPbouiCOM.BoGridColumnType.gct_CheckBox
oGrid.CollapseLevel = 0
oForm.Freeze(False)
ElseIf (userDS.Value = 2) Then
oForm.Freeze(True)
oForm.DataSources.DataTables.Item(0).ExecuteQuery("Select TOP 3000 CardCode, CardName, DocDate, DocEntry, DocNum, DocTotal, DocStatus, U_HandOver, ShipToCode from OINV where U_HandOver IS NULL ")
oGrid.Columns.Item("U_HandOver").Type = SAPbouiCOM.BoGridColumnType.gct_CheckBox
oGrid.CollapseLevel = 1
oForm.Freeze(False)
End If
End If
If (FormUID = "frmGrid") And (pVal.BeforeAction = False) And _
(pVal.EventType = SAPbouiCOM.BoEventTypes.et_CLICK) And _
((pVal.ItemUID = "btnCol") Or (pVal.ItemUID = "btnExp")) Then
If (pVal.ItemUID = "btnCol") Then
oGrid.Rows.CollapseAll()
End If
If (pVal.ItemUID = "btnExp") Then
oGrid.Rows.ExpandAll()
End If
End If
If FormUID = "frmGrid" And pVal.BeforeAction = False _
And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED _
And pVal.ColUID = "U_HandOver" Then
Dim newColor As Integer = If(oGrid.DataTable.GetValue("U_HandOver", oGrid.GetDataTableRowIndex(pVal.Row)).ToString() = "Y", 16777088, 15198183)
oGrid.CommonSetting.SetRowBackColor(pVal.Row + 1, newColor)
End If
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pedro,
Thanks for your reply.
I replaced this line:
oGrid.CommonSetting.SetRowBackColor(pVal.Row + 1, newColor)
by this line:
oGrid.CommonSetting.SetRowBackColor(oGrid.GetDataTableRowIndex(pVal.Row + 1), newColor)
and here are the results:
Best Regards,
Leon
Message was edited by: Leon Lai Kan ----------------------------------------------------------
Hi, I added a MessageBox to trace the row numbers:
oGrid.CommonSetting.SetRowBackColor(pVal.Row + 1, newColor)
SBO_Application.MessageBox(pVal.Row)
... and I found something interesting, which explains my strange result, and may help to solve the problem:
It appears that pVal.Row does not give the absolute row number of the ticked row.
Rather it gives the Row Number as it appears on the screen (i.e excluding the rows hidden by collapse)
With MATRIX, there is a function called VisualRow. There is no such function (?) with GRID. Any workaround? Leon Lai
Hi Leon,
I had this issue in the past and remember it was driving me crazy...
But in the end I found a solution, maybe it helps you ( it is just a quick n dirty workaround ) :
if (FormUID == theFormUID && !pVal.BeforeAction && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "MyGrid" && pVal.ColUID == "U_Handover")
{
int expandedleafs = 0;
int countbranch = 0;
bool lastbranchExpanded = true;
for (int i = 0; i <= pVal.Row; i++)
{
if (!oGrid.Rows.IsLeaf(i))
{
lastbranchExpanded = oGrid.Rows.IsExpanded(i);
countbranch++;
}
else
{
if (lastbranchExpanded)
{
expandedleafs++;
}
}
}
int newColor = oGrid.DataTable.GetValue("U_Handover", oGrid.GetDataTableRowIndex(pVal.Row)).ToString() == "Y" ? 16777215 : 8421504;
oGrid.CommonSetting.SetRowBackColor((expandedleafs + countbranch), newColor);
}
Basically I count the branches ( are they called like this ? ) and the expanded leaf rows, et voila you got the visual row. Btw for my understanding there is a problem with the isExpanded method - for leaf rows it seems to be always collapsed.
regards,
Maik
Hi Maik
I know this thread is closed, but I don't want to open a new thread as it would require too much explanation.
As I said, your formula works wonders. But it has puzzled me for months!
I spent so many sleepless nights that I finally decided to knock at your door.
Hope you won't mind replying a closed thread.
Here it is, VB.NET version:
If FormUID = "HandOver" And pVal.BeforeAction = False _
And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED _
And pVal.ColUID = "HandOver" Then
Dim expandedleafs As Integer = 0
Dim countbranch As Integer = 0
Dim lastbranchExpanded As Boolean = True
For i As Integer = 0 To pVal.Row
If Not oGrid.Rows.IsLeaf(i) Then
lastbranchExpanded = oGrid.Rows.IsExpanded(i)
countbranch += 1
Else
If oGrid.Rows.IsLeaf(i) Then
If lastbranchExpanded = True Then
expandedleafs += 1
End If
End If
End If
Next
Dim newColor As Integer = If(oGrid.DataTable.GetValue("HandOver", oGrid.GetDataTableRowIndex(pVal.Row)).ToString() = "Y", 16777088, 15198183)
oGrid.CommonSetting.SetRowBackColor((expandedleafs + countbranch), newColor)
End If
----------------------
I cannot understand at all how the value of lastbranchExpanded suddenly changes to TRUE.
If the row i is a leaf, the code nowhere evaluates lastbranchExpanded to TRUE.
So, how does TRUE appear?
See also my simplified flowchart.
Best Regards,
Leon Lai
Hi Maik,
Thanks for your reply, but I'm still shrouded in mystery.
>> the value is set in the row before :
>> 1. row is leaf
>> 2.lastbranchExpanded = true
Do you mean this line?
Dim lastbranchExpanded As Boolean = True
Even if I set it = False, the code works perfectly!
Anyway, it is = True only initially.
If the row is a leaf, this value is set to = False, so it is no longer = True
----------
If the row IS NOT a leaf, this code is executed:
If Not oGrid.Rows.IsLeaf(i) Then
lastbranchExpanded = oGrid.Rows.IsExpanded(i)
and it returns False.
Yes! Here lastbranchExpanded IS INDEED EVALUATED (to False)
But if the row IS a leaf, the above code IS NOT executed
and hence, there is nothing to set the value of lastbranchExpanded to True.
Notice that the initial value (True) has already changed to False.
Nowhere in your code is there something to set the value of lastbranchExpanded to True
Your code only says that if lastbranchExpanded =True, then expandedleafs += 1
I still cannot see WHERE the value of lastbranchExpanded is set to TRUE in the first place.
Really,I am in thick mud. Hope you can enlighten me!
Best Regards,
Leon
I try to ellaborate.
You have the given rows :
rownr branch/leaf expanded
0 branch true
1 leaf not interesting
2 leaf not interesting
3 branch false
4 NOT Visible
5 NOT Visible
6 NOT Visible
7 branch true
8 leaf not interesting
values in the loop :
rownr countbranch expandedleafs lastbranchExpanded
0 1 0 true
1 1 1 true
2 1 2 true
3 2 2 false
4 2 2 false
5 2 2 false
6 2 2 false
7 3 2 true
8 3 3 true
This line lastbranchExpanded = oGrid.Rows.IsExpanded(i)
is only executed for branches and it just determines if the following leaves have to be counted ( because in the collection the rows exist anyway ).
If all branches are expanded all leaf rows are counted
regrads,
Maik
User | Count |
---|---|
110 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.