on 11-07-2012 2:56 PM
Hi
I have created Grid , it is giving me error "Item already exists [66000-13] Form Unique ID : F_28, Item Unique ID : MyGrid
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
I want that if Grid already exists then it should not recreate Grid
Thanks
Hi Sunny,
You should learn how to debug your application.
When you browse for a record, your application threw an error.
The error is in the Form Data Load Event on this line :
Dim oGrid As SAPbouiCOM.Grid = oForm.Items.Item("MyGrid")
Change it to this :
Dim oGrid As SAPbouiCOM.Grid = oForm.Items.Item("MyGrid").Specific
Second, if you dont want the data to show when you first load your form, then remove the
Try
oForm.DataSources.DataTables.Add("MyDataTable")
Catch
End Try
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
from your Form Load Event.
Regards
Edy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sunny,
But you need to do some fine tuning on your logic here.
The Grid should not be re-added in the first place.
You need to rethink when (which event) you should create the Grid.
Since an item should never be added twice in a specific form, the best place to add an item in a form is during the Form Load event.
This event is only triggered once during the lifetime of the form.
Hence, you will need to worry about adding the item twice.
Regards
Edy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Edy
First time it works when i open again it gives error (The Server threw an exception ,Exception from HRESULT : 0*800110105)
Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent
If ((BusinessObjectInfo.FormTypeEx = "60100" And BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_LOAD) And (BusinessObjectInfo.BeforeAction = False)) Then
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
oGrid = oNewItem.Specific
End If
End Sub
Thanks
Hi Sunny,
Of course it will throw you an item exist error.
You are adding it on the FormDataLoad event.
I think you have mixed between FormDataLoadEvent and FormLoadEvent.
the two of them are different event.
1. Form Load event triggers when you first call up a form. And it will be only 1 time through the form life. This event is under (Private Sub SBO_Application_ItemEvent)
2. Form Data Load event triggers when you browse / find a record on an existing form. So, this event can be triggered multiple times during the form life. This event is under (Private Sub SBO_Application_FormDataEvent)
You should draw your items on the FORM LOAD (1) event.
Can you try to move the Item Add into the correct event ?
Regards
Edy
Hi
How can i change this code to check if Grid already exists then it should not recreate
Private Sub CreateForm()
Try
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
oGrid = oNewItem.Specific
oForm.DataSources.DataTables.Add("MyDataTable")
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
oGrid.Columns.Item(0).Width = 50
oGrid.Columns.Item(1).Width = 125
oGrid.Columns.Item(2).Width = 75
Catch oEx As Exception
MessageBox.Show(oEx.Message)
Finally
GC.Collect()
End Try
End Sub
Thanks
Hi Sunny,
If you insists (This is a VERY BAD programming. SHOULD AVOID this whenever possible):
Private Sub CreateForm()
Try
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
Catch oEx As Exception
oNewItem = oForm.Items.Item("MyGrid")
Finally
GC.Collect()
End Try
oGrid = oNewItem.Specific
Try
oForm.DataSources.DataTables.Add("MyDataTable")
Catch
End Try
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
oGrid.Columns.Item(0).Width = 50
oGrid.Columns.Item(1).Width = 125
oGrid.Columns.Item(2).Width = 75
End Sub
Regards
Edy
Hi Edy
I have done like this , it's working . Is it o.k or u see any change to be done
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If ((pVal.FormTypeEx = "60100" And pVal.EventType <> SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD) And (pVal.Before_Action = True)) Then
oForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)
If pVal.ItemUID = "UserFolder" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED And pVal.Before_Action = True Then
oForm.PaneLevel = 8
Try
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
Catch oEx As Exception
oNewItem = oForm.Items.Item("MyGrid")
End Try
oGrid = oNewItem.Specific
CreateForm()
End If
End If
End sub
Private Sub CreateForm()
Try
Try
oForm.DataSources.DataTables.Add("MyDataTable")
Catch
End Try
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
oGrid.Columns.Item(0).Width = 50
oGrid.Columns.Item(1).Width = 125
oGrid.Columns.Item(2).Width = 75
Catch oEx As Exception
MessageBox.Show(oEx.Message)
Finally
GC.Collect()
End Try
End Sub
Thanks
Hi Sunny,
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
Dim oForm As SAPbouiCOM.Form
Dim oItem, oNewItem As SAPbouiCOM.Item
Dim oGrid As SAPbouiCOM.Grid
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.BeforeAction = False Then
oForm = SBO_Application.Forms.Item(pVal.FormUID)
'On After Form Load Create everything you need on this form :
'1. Create the Folder
'I think you have something already here. You need to keep you existing adding of folder here.
'2. Create the Grid Item
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
oGrid = oNewItem.Specific
'3. Also add the Data Source
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
End If
If ((pVal.FormTypeEx = "60100" And pVal.EventType <> SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD) And (pVal.Before_Action = True)) Then
oForm = SBO_Application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)
If pVal.ItemUID = "UserFolder" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED And pVal.Before_Action = True Then
'Here you will need only to set the pane level to show your items.
oForm.PaneLevel = 8
End If
End If
End Sub
Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent
'On Form Data Load, refresh your grid and datatable content.
If ((BusinessObjectInfo.FormTypeEx = "60100" And BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_LOAD) And (BusinessObjectInfo.BeforeAction = False)) Then
Dim oForm As SAPbouiCOM.Form = Me.SBO_Application.Forms.Item(BusinessObjectInfo.FormUID)
Dim oGrid As SAPbouiCOM.Grid = oForm.Items.Item("MyGrid")
Dim oDT As SAPbouiCOM.DataTable = oGrid.DataTable
oDT.ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oDT
oGrid.Columns.Item(0).Width = 50
oGrid.Columns.Item(1).Width = 125
oGrid.Columns.Item(2).Width = 75
End If
End Sub
Hi Edy
I have written below code . Problem 1 is it is not displaying Grid . Secondly when i click on NewFolder tab 'O.K' button changes to Update which should not . It should only change if some changes are done.
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If ((pVal.FormTypeEx = "60100" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.BeforeAction = False)) Then
'If pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.BeforeAction = False Then
oForm = SBO_Application.Forms.Item(pVal.FormUID)
oForm.DataSources.UserDataSources.Add("FolderDS", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 1)
oNewItem = oForm.Items.Add("UserFolder", SAPbouiCOM.BoFormItemTypes.it_FOLDER)
oItem = oForm.Items.Item("147")
oNewItem.Top = oItem.Top
oNewItem.Height = oItem.Height
oNewItem.Width = oItem.Width
oNewItem.Left = oItem.Left + oItem.Width
oFolderItem = oNewItem.Specific
oFolderItem.Caption = "NewTab"
oFolderItem.GroupWith("147")
oForm.PaneLevel = 1
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
oGrid = oNewItem.Specific
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
End If
end sub
Thanks
Hi Sunny,
For problem 1,
The application error because you have not add the DataTable,
Use this after your line :
oForm.DataSources.UserDataSources.Add("FolderDS", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 1)
oForm.DataSources.DataTables.Add("MyDataTable")
For your Second Problem :
Set this when you create your folder item :
oNewItem = oForm.Items.Add("UserFolder", SAPbouiCOM.BoFormItemTypes.it_FOLDER)
oNewItem.AffectsFormMode = False
Regards
Edy
Hi Edy
Problem i am facing now is Grid appears on Blank record , on existing record Grid does not appear . Secondly when i close the form & re-opens again the NewTab does not appear.
Private Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.FormDataEvent
If ((BusinessObjectInfo.FormTypeEx = "60100" And BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_LOAD) And (BusinessObjectInfo.BeforeAction = False)) Then
Dim oForm As SAPbouiCOM.Form = Me.SBO_Application.Forms.Item(BusinessObjectInfo.FormUID)
Dim oGrid As SAPbouiCOM.Grid = oForm.Items.Item("MyGrid")
Dim oDT As SAPbouiCOM.DataTable = oGrid.DataTable
oDT.ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV ")
oGrid.DataTable = oDT
oGrid.Columns.Item(0).Width = 50
oGrid.Columns.Item(1).Width = 125
oGrid.Columns.Item(2).Width = 75
End If
Endif
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If ((pVal.FormTypeEx = "60100" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_LOAD And pVal.BeforeAction = False)) Then
oForm = SBO_Application.Forms.Item(pVal.FormUID)
oForm.DataSources.UserDataSources.Add("FolderDS", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 1)
oNewItem = oForm.Items.Add("UserFolder", SAPbouiCOM.BoFormItemTypes.it_FOLDER)
oNewItem.AffectsFormMode = False
oItem = oForm.Items.Item("147")
oNewItem.Top = oItem.Top
oNewItem.Height = oItem.Height
oNewItem.Width = oItem.Width
oNewItem.Left = oItem.Left + oItem.Width
oFolderItem = oNewItem.Specific
oFolderItem.Caption = "NewTab"
oFolderItem.GroupWith("147")
oForm.PaneLevel = 1
oItem = oForm.Items.Item("15")
oNewItem = oForm.Items.Add("MyGrid", SAPbouiCOM.BoFormItemTypes.it_GRID)
oNewItem.FromPane = 8
oNewItem.ToPane = 8
oNewItem.Left = oItem.Left + 125
oNewItem.Top = oItem.Top
oNewItem.Width = 275
oNewItem.Height = 175
oGrid = oNewItem.Specific
Try
oForm.DataSources.DataTables.Add("MyDataTable")
Catch
End Try
oForm.DataSources.DataTables.Item(0).ExecuteQuery("select CardCode, CardName, DocDate, DocNum, DocTotal, DocStatus from OINV")
oGrid.DataTable = oForm.DataSources.DataTables.Item("MyDataTable")
End If
End sub
Thanks
Hi Sunny,
A quick way to check if an item exists is to do try catch block around it.
bool ItemExists(Form oForm, string ItemUid)
{
Item oItem;
try
{
oItem = oForm.Items.Item(ItemUid);
}
catch(Exception e)
{
// item does not exist
return false;
}
return true;
}
Best regards,
Pedro Magueija
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
107 | |
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.