cancel
Showing results for 
Search instead for 
Did you mean: 

matrix focus problem when assigning value to a cell using vb.net

Former Member
0 Kudos

Hi Guys,
Everytime i pressed the tab button in Itemcode,Quantity,price,Discrate1...DiscRate5 columns, the CURSOR is focusing in the DiscAmt's and DiscNet's.. its like the cursor is moving  in every cell becouse of auto computation... what i want is when i press the tab key,the cursor will not move in the column that updating.

heres my code.

  If (((pVal.FormType = "139") Or (pVal.FormType = "142")) And (pVal.ItemUID = "38") And _

              (pVal.EventType = SAPbouiCOM.BoEventTypes.et_KEY_DOWN)) Then

            'SO

            If (pVal.FormType = "139") Then

                oForm = SBO_Application.Forms.GetForm(139, 0)

            End If

            'PO

            If (pVal.FormType = "142") Then

                oForm = SBO_Application.Forms.GetForm(142, 0)

            End If

            oMatrix = oForm.Items.Item("38").Specific

            If ((pVal.ColUID = "1") Or (pVal.ColUID = "14") Or pVal.ColUID = "11" Or pVal.ColUID = "U_DiscRate1" Or pVal.ColUID = "U_DiscRate2" Or _

                pVal.ColUID = "U_DiscRate3" Or pVal.ColUID = "U_DiscRate4" Or pVal.ColUID = "U_DiscRate5") And _

                (pVal.BeforeAction = False) And (pVal.CharPressed = "9") Then

                '---loop the matrix and get the row selected

                For i As Integer = 1 To oMatrix.VisualRowCount

                    If i = pVal.Row Then

                        Dim itemcode As String = oMatrix.Columns.Item("1").Cells.Item(i).Specific.value.ToString

                        If (itemcode = "" Or itemcode.Length = 0) Then

                            Exit Sub

                        End If

                        Dim Quantity As Integer = oMatrix.Columns.Item("11").Cells.Item(i).Specific.value.ToString

                        Dim Price As Decimal = oMatrix.Columns.Item("14").Cells.Item(i).Specific.value.ToString

                        Dim Total As Decimal = Quantity * Price

                        Dim DiscRate1 As Decimal = oMatrix.Columns.Item("U_DiscRate1").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt1 As Decimal

                        Dim DiscNet1 As Decimal

                        If (DiscRate1 > 0) Then

                            DiscAmt1 = DiscRate1 * Total

                            DiscNet1 = Total - DiscAmt1

                            oMatrix.Columns.Item("U_DiscAmt1").Cells.Item(i).Specific.value = DiscAmt1

                            oMatrix.Columns.Item("U_NetAmt1").Cells.Item(i).Specific.value = DiscNet1

                        Else

                            DiscAmt1 = 0

                            DiscNet1 = 0

                            oMatrix.Columns.Item("U_DiscAmt1").Cells.Item(i).Specific.value = DiscAmt1

                            oMatrix.Columns.Item("U_NetAmt1").Cells.Item(i).Specific.value = DiscNet1

                        End If

                        Dim DiscRate2 As Decimal = oMatrix.Columns.Item("U_DiscRate2").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt2 As Decimal

                        Dim DiscNet2 As Decimal

                        If (DiscRate2 > 0 And DiscRate1 > 0) Then

                            DiscAmt2 = DiscNet1 * DiscRate2

                            DiscNet2 = DiscNet1 - DiscAmt2

                            oMatrix.Columns.Item("U_DiscAmt2").Cells.Item(i).Specific.value = DiscAmt2

                            oMatrix.Columns.Item("U_DiscNet2").Cells.Item(i).Specific.value = DiscNet2

                        Else

                            DiscAmt2 = 0

                            DiscNet2 = 0

                            oMatrix.Columns.Item("U_DiscAmt2").Cells.Item(i).Specific.value = DiscAmt2

                            oMatrix.Columns.Item("U_DiscNet2").Cells.Item(i).Specific.value = DiscNet2

                        End If

                        Dim DiscRate3 As Decimal = oMatrix.Columns.Item("U_DiscRate3").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt3 As Decimal

                        Dim DiscNet3 As Decimal

                        If (DiscRate3 > 0 And DiscRate1 > 0 And DiscRate2 > 0) Then

                            DiscAmt3 = DiscNet2 * DiscRate3

                            DiscNet3 = DiscNet2 - DiscAmt3

                            oMatrix.Columns.Item("U_DiscAmt3").Cells.Item(i).Specific.value = DiscAmt3

                            oMatrix.Columns.Item("U_DiscNet3").Cells.Item(i).Specific.value = DiscNet3

                        Else

                            DiscAmt3 = 0

                            DiscNet3 = 0

                            oMatrix.Columns.Item("U_DiscAmt3").Cells.Item(i).Specific.value = DiscAmt3

                            oMatrix.Columns.Item("U_DiscNet3").Cells.Item(i).Specific.value = DiscNet3

                        End If

                        Dim DiscRate4 As Decimal = oMatrix.Columns.Item("U_DiscRate4").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt4 As Decimal

                        Dim DiscNet4 As Decimal

                        If (DiscRate4 > 0 And DiscRate1 > 0 And DiscRate2 > 0 And DiscRate3 > 0) Then

                            DiscAmt4 = DiscNet3 * DiscRate4

                            DiscNet4 = DiscNet3 - DiscAmt4

                            oMatrix.Columns.Item("U_DiscAmt4").Cells.Item(i).Specific.value = DiscAmt4

                            oMatrix.Columns.Item("U_DiscNet4").Cells.Item(i).Specific.value = DiscNet4

                        Else

                            DiscAmt4 = 0

                            DiscNet4 = 0

                            oMatrix.Columns.Item("U_DiscAmt4").Cells.Item(i).Specific.value = DiscAmt4

                            oMatrix.Columns.Item("U_DiscNet4").Cells.Item(i).Specific.value = DiscNet4

                        End If

                        Dim DiscRate5 As Decimal = oMatrix.Columns.Item("U_DiscRate5").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt5 As Decimal

                        Dim DiscNet5 As Decimal

                        If (DiscRate5 > 0 And DiscRate4 > 0 And DiscRate1 > 0 And DiscRate2 > 0 And DiscRate3 > 0) Then

                            DiscAmt5 = DiscNet4 * DiscRate5

                            DiscNet5 = DiscNet4 - DiscAmt5

                            oMatrix.Columns.Item("U_DiscAmt5").Cells.Item(i).Specific.value = DiscAmt5

                            oMatrix.Columns.Item("U_DiscNet5").Cells.Item(i).Specific.value = DiscNet5

                        Else

                            DiscAmt5 = 0

                            DiscNet5 = 0

                            oMatrix.Columns.Item("U_DiscAmt5").Cells.Item(i).Specific.value = DiscAmt5

                            oMatrix.Columns.Item("U_DiscNet5").Cells.Item(i).Specific.value = DiscNet5

                        End If

                        ' oForm.Items.Item("24").Specific.value = TotalDiscRate

                        Exit For

                    End If

                Next

                '---loop the matrix and get the row selected

                '---total discRates

                Dim TotalDiscRate As Double = 0.0

                For i As Integer = 1 To oMatrix.VisualRowCount

                    Dim ItemCode As String = oMatrix.Columns.Item("1").Cells.Item(i).Specific.value.ToString

                    If (ItemCode.Length > 0) Then

                        Dim Rate1 As Decimal = oMatrix.Columns.Item("U_DiscAmt1").Cells.Item(i).Specific.value.ToString

                        Dim Rate2 As Decimal = oMatrix.Columns.Item("U_DiscAmt2").Cells.Item(i).Specific.value.ToString

                        Dim Rate3 As Decimal = oMatrix.Columns.Item("U_DiscAmt3").Cells.Item(i).Specific.value.ToString

                        Dim Rate4 As Decimal = oMatrix.Columns.Item("U_DiscAmt4").Cells.Item(i).Specific.value.ToString

                        Dim Rate5 As Decimal = oMatrix.Columns.Item("U_DiscAmt5").Cells.Item(i).Specific.value.ToString

                        TotalDiscRate += Rate1 + Rate2 + Rate3 + Rate4 + Rate5

                        oForm.Items.Item("42").Specific.value = TotalDiscRate

                    End If

                Next

                '---total discRates

            End If

        End If

    End Sub

Accepted Solutions (1)

Accepted Solutions (1)

maik_delly
Active Contributor
0 Kudos

Hi Weynard,

if I understand correctly you are searching for the freeze method of form.

Before writing/computing the values use oform.freeze(true) and when you are finished oform.freeze(false).

It is a good idea to use a try catch finally block and unfreeze in finally.

regards,

Maik

Former Member
0 Kudos

the oform.freeze(false) is not working. the form is freezing after the computation

this is my code:

oform.freeze(true)

oMatrix.Columns.Item("U_DiscAmt1").Cells.Item(i).Specific.value = DiscAmt1

oMatrix.Columns.Item("U_NetAmt1").Cells.Item(i).Specific.value = DiscNet1

oform.freeze(false)

maik_delly
Active Contributor
0 Kudos

Hi Weynard,

you have to make sure to have one oform.freeze(false) for every oform.freeze(true) - so you can't freeze it 2 times and unfreeze only once.

regards,

Maik

Former Member
0 Kudos

the mouse cursor is still focusing in the DisNet5 for every column.

I dont know why its focusing eventhough i used the oform.freeze(true) before computing.

this is my updated cood code:

For i As Integer = 1 To oMatrix.VisualRowCount

                        oForm.Freeze(True)

                        Dim itemcode As String = oMatrix.Columns.Item("1").Cells.Item(i).Specific.value.ToString

                        If (itemcode = "" Or itemcode.Length = 0) Then

                            oMatrix.Columns.Item("1").Cells.Item(i).Specific.value = ""

                            oForm.Freeze(False)

                            Exit For

                        End If

                        Dim Quantity As Integer = oMatrix.Columns.Item("11").Cells.Item(i).Specific.value.ToString

                        Dim Price As Decimal = oMatrix.Columns.Item("14").Cells.Item(i).Specific.value.ToString

                        Dim Total As Decimal = Quantity * Price

                        Dim DiscRate1 As Decimal = oMatrix.Columns.Item("U_DiscRate1").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt1 As Decimal

                        Dim DiscNet1 As Decimal

                        If (DiscRate1 > 0) Then

                            DiscAmt1 = DiscRate1 * Total

                            DiscNet1 = Total - DiscAmt1

                            oMatrix.Columns.Item("U_DiscAmt1").Cells.Item(i).Specific.value = DiscAmt1

                            oMatrix.Columns.Item("U_NetAmt1").Cells.Item(i).Specific.value = DiscNet1

                        Else

                            DiscAmt1 = 0

                            DiscNet1 = 0

                            oMatrix.Columns.Item("U_DiscAmt1").Cells.Item(i).Specific.value = DiscAmt1

                            oMatrix.Columns.Item("U_NetAmt1").Cells.Item(i).Specific.value = DiscNet1

                        End If

                        'code here is for computing Discounts for 2 to 4. i didnt copy the code here because its too long to read. the syntax for discout 2 - 4 is same wtith Discount 1 ^

     

                        Dim DiscRate5 As Decimal = oMatrix.Columns.Item("U_DiscRate5").Cells.Item(i).Specific.value.ToString

                        Dim DiscAmt5 As Decimal

                        Dim DiscNet5 As Decimal

                        If (DiscRate5 > 0 And DiscRate4 > 0 And DiscRate1 > 0 And DiscRate2 > 0 And DiscRate3 > 0) Then

                            DiscAmt5 = DiscNet4 * DiscRate5

                            DiscNet5 = DiscNet4 - DiscAmt5

                            oMatrix.Columns.Item("U_DiscAmt5").Cells.Item(i).Specific.value = DiscAmt5

                            oMatrix.Columns.Item("U_DiscNet5").Cells.Item(i).Specific.value = DiscNet5

                        Else

                            DiscAmt5 = 0

                            DiscNet5 = 0

                            oMatrix.Columns.Item("U_DiscAmt5").Cells.Item(i).Specific.value = DiscAmt5

                            oMatrix.Columns.Item("U_DiscNet5").Cells.Item(i).Specific.value = DiscNet5

                        End If

                        oForm.Freeze(False)

                    Next

pedro_magueija
Active Contributor
0 Kudos

Hi Weynard,

The focus moves to that column because you are putting a value in it. The freeze prevents flickering of the screen.

You can try the oMatrix.SetCellWithoutValidation(...) but this method only works for UDF's.

I haven't tried it yet, so I don't know if it will also move the focus.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

i dont have any UDF's in Sales Order. so icant use oMatrix.SetCellWithoutValidation(...)

pedro_magueija
Active Contributor
0 Kudos

Hi Weynard,

Looking at your code I can see some UDF's:

oMatrix.Columns.Item("U_DiscAmt5").Cells.Item(i).Specific.value...


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Answers (0)