cancel
Showing results for 
Search instead for 
Did you mean: 

Invalid Item in Form Load Event

Former Member
0 Kudos

Hello,

i have a problem to access items in Form Load Event. If I use a form created with screen painter and I want to set some values to items (EditText, Grid, ComboBox) in FormLoad event. I get a message "invalid item". Same if I use the event FormActivate. Is it a bug? And if yes, when do you fix it?

Best regards,

Alexander

Accepted Solutions (0)

Answers (2)

Answers (2)

marco_laporta
Participant
0 Kudos

Hi Alexander.

do you use the LoadBatchActions method to load your form from XML? For example if you use B1XmlFormMenu class in the B1WizardBase, this class surely use LoadBatchActions method.

I Think, like Edy Simon, that, for a form, the Load event fires before LoadBatchActions is completed, and in particular before LoadBatchActions has created all the items

So you can try this:

Solution 1). Move you code from the Load Event to another function that you can call after LoadBatchActions statement, for example adding code after LoadForm method in each class thet extends B1XmlFormMenu (if you use B1WizardBase).

Solution 2). Try something similar at what was done in class B1FolderMgr in the B1WizardBase project, with a new Thread that wait for LoadBatchActions compete.

Regards

Marco

Edited by: marco.laporta on Feb 22, 2010 10:12 AM

Former Member
0 Kudos

Hi Alex,

Can you post the code where you're getting the error?

Regards,

Vítor Vieira

Former Member
0 Kudos

Hi Vitor,

actually I'm always getting an error by loading a "screen painter" form. Not only in the code below.


 Private Sub moSBOApplication_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles sboApplication.ItemEvent
        Try
            If pVal.FormTypeEx <> "frmPlan" Then Exit Sub
            Select Case pVal.EventType
                Case BoEventTypes.et_FORM_LOAD
                    If pVal.BeforeAction = True Then Exit Sub
                    oForm = sboApplication.Forms.GetForm(pVal.FormTypeEx, pVal.FormTypeCount)
                    oForm.EnableMenu("1288", True)
                    oForm.EnableMenu("1289", True)
                    oForm.EnableMenu("1290", True)
                    oForm.EnableMenu("1291", True)
                    initGridAD(oForm)
                Case BoEventTypes.et_FORM_ACTIVATE
                    If pVal.BeforeAction = True Then Exit Sub
                    oForm = sboApplication.Forms.GetForm(pVal.FormTypeEx, pVal.FormTypeCount)
                    initGridAD(oForm)
            End Select

        Catch ex As Exception
            sboApplication.SetStatusBarMessage(ex.ToString(), BoMessageTime.bmt_Short, True)
        End Try
    End Sub

    Private Sub initGridAD(ByVal oForm As Form)
        Dim oGrid As Grid = oForm.Items.Item("gridAD").Specific  ' *here I'm gettig an error*
        Dim oDataTable As SAPbouiCOM.DataTable = oForm.DataSources.DataTables.Item("DTgridAD")
        If not oDataTable.Rows.Count = 0 Then Exit Function
        oGrid.DataTable.ExecuteQuery("Select '' as 'Choose', SlpCode as Code, SlpName as 'Name' From OSLP")
        oGrid.Columns.Item("Choose").Type = BoGridColumnType.gct_CheckBox
    End Sub

Best Regards,

Alexander

Edited by: AlexF80 on Feb 17, 2010 4:59 PM

Former Member
0 Kudos

Hi Alex,

Make sure the form has an item with the ID "gridAD". Remember it is case sensitive, to gridAD <> GridAD <> gridad...

You can use the oForm.GetAsXML() method to check all the items in the form.

Regards,

Vítor Vieira

Former Member
0 Kudos

Hi Vìtor,

I'm sure because the code doesn't work only in these two events.

Regards,

Alexander

Former Member
0 Kudos

Hi Alex,

I haven't try the code, but I think there are just one things to try.

I think, is convenient to use the FormUID params to retrive the form instead the use of Forms.GetForm() method.

Please try this one and let us know the result.


Private Sub moSBOApplication_ItemEvent( _
                        ByVal FormUID As String, _
                        ByRef pVal As SAPbouiCOM.ItemEvent, _
                        ByRef BubbleEvent As Boolean) Handles sboApplication.ItemEvent

    Try
        If Not (pVal.FormTypeEx = "frmPlan") Then Exit Sub
        Select Case pVal.EventType
            Case BoEventTypes.et_FORM_LOAD
                If pVal.BeforeAction = True Then Exit Sub
                oForm = sboApplication.Forms.Item(FormUID) ' try this one
                oForm.EnableMenu("1288", True)
                oForm.EnableMenu("1289", True)
                oForm.EnableMenu("1290", True)
                oForm.EnableMenu("1291", True)
                initGridAD(oForm)
            Case BoEventTypes.et_FORM_ACTIVATE
                If pVal.BeforeAction = True Then Exit Sub
                oForm = sboApplication.Forms.Item(FormUID) ' try this one
                initGridAD(oForm)
        End Select

    Catch ex As Exception
        sboApplication.SetStatusBarMessage(ex.ToString(), BoMessageTime.bmt_Short, True)
    End Try
End Sub

Private Sub initGridAD(ByVal oForm As Form)
    Dim oGrid As Grid = oForm.Items.Item("gridAD").Specific  ' *here I'm gettig an error*
    Dim oDataTable As SAPbouiCOM.DataTable = oForm.DataSources.DataTables.Item("DTgridAD")

    If not oDataTable.Rows.Count = 0 Then Exit Function
    oGrid.DataTable.ExecuteQuery("Select '' as 'Choose', SlpCode as Code, SlpName as 'Name' From OSLP")
    oGrid.Columns.Item("Choose").Type = BoGridColumnType.gct_CheckBox
End Sub

Is this code hosted in a module or in a class?

If is in a class, how many instancens of class exist when you get the error?

Hope this helps.

Carmine