on 09-19-2008 12:42 PM
i have taken combo box in form . i want to select define new option in combo box.
is it possible....?
Hi
this is the method what I have used in the form with matrix what have the combobox column.
Hope to help
BR
Sierdna S.
CREATE FORM SUB
Public Sub CreateForm(...)
...
If oMatrix.RowCount > 0 Then
Call InitializeMatrixCombo(oForm, _
MatrixID, _
"DSU_Linked", _ ' Combobox Column
"@LINKED_TABLE", _
"<Default_Value>" _
)
End If
...
End Sub
InitComboBox sub when we initializing combobox to combobox values we add also 2 new values:
- "","" : NULL value, if database column accept null value
- "Redefine","Redefine" : When selected with ItemEvent we activating menu with form uid where are we can define new values.
Public Sub InitializeMatrixCombo( _
ByRef oForm As SAPbouiCOM.Form, _
ByVal sMatrixID As String, _
ByVal sComboColumnName As String, _
ByVal sLinkedTable As String, _
Optional ByVal sDefaultValue As String = "" _
)
Try
oForm.Freeze(True)
If SBO_Company.Connect Then
'
' Matrix
Dim oMatrix As SAPbouiCOM.Matrix
oMatrix = oForm.Items.Item(sMatrixID).Specific
If oMatrix Is Nothing Then Throw New Exception("ERROR: matrix object is nothing"))
'
' Matrix column
Dim oColumn As SAPbouiCOM.Column
oColumn = oMatrix.Columns.Item(sComboColumnName)
'
' Matrix column cell
Dim oCell As SAPbouiCOM.Cell
oCell = oColumn.Cells.Item(oMatrix.VisualRowCount)
'
' Matrix column cell combo
Dim oCombo As SAPbouiCOM.ComboBox
oCombo = oCell.Specific
If ClearCombo(oCombo) Then
Try
' Add 1-st value if database field accept NULL
oCombo.ValidValues.Add("", "")
Dim oRS As SAPbobsCOM.Recordset
oRS = SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Dim sSql As String = "SELECT Code, Name FROM [@" & sLinkedTable & "] ORDER BY 1"
oRS.DoQuery(sSql)
oRS.MoveFirst()
While oRS.EoF = False
oCombo.ValidValues.Add(oRS.Fields.Item("Code").Value, _
oRS.Fields.Item("Name").Value)
oRS.MoveNext()
End While
' Add DEFINE NEW value +++++++++++++++++++++++++++++++
' Note: Code can have length up to 8 caracters
oCombo.ValidValues.Add("Redefine", "Redefine")
If Not oRS Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS)
oRS = Nothing
End If
System.GC.Collect() 'Release the handle to the table
' Select dafault value if not null
If Not sDefaultValue.Equals("") Then
If oCombo.ValidValues.Count > 0 Then
oCombo.Select(sDefaultValue, SAPbouiCOM.BoSearchKey.psk_ByValue)
End If
Else
If oCombo.ValidValues.Count >= 1 Then
oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
End If
End If
Catch ex As Exception
' log exception
Finally
oCombo = Nothing
oCell = Nothing
oColumn = Nothing
oMatrix = Nothing
End Try
End If
End If
Catch ex As Exception
' log exception
Finally
oForm.Freeze(False)
System.GC.Collect() 'Release the handle to the table
End Try
End Sub
Item Event to handle selection of "Redefine" voice in combobox.
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
oForm = SBO_Application.Forms.Item(FormUID)
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_COMBO_SELECT _
And pVal.FormUID = sgloFormUID _
And pVal.ItemUID = MatrixID _
And pVal.ColUID = "DSU_Linked" _
And pVal.BeforeAction = False _
And pVal.ItemChanged = True _
Then
Try
Dim oMatrix As SAPbouiCOM.Matrix
oMatrix = oForm.Items.Item(MatrixID).Specific
If oMatrix Is Nothing Then Throw New Exception("ERROR: matrix object is nothing")
Try
Dim oCombo As SAPbouiCOM.ComboBox
Dim sValue As String = ""
oCombo = oMatrix.Columns.Item("DSU_Linked").Cells.Item(pVal.Row).Specific
sValue = oCombo.Selected.Value
If sValue.Equals("Redefine") Then
Try
oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
oForm.Refresh()
Catch ex As Exception
' log exception
End Try
'
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Here place your menu uid to call the form for adding new value
' +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SBO_Application.Menus.Item("51207").Activate()
'
End If
BubbleEvent = False
Catch ex1 As Exception
' log exception
End Try
Catch ex As Exception
' log exception
End Try
End If
' Other events +++
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Imports SAPbobsCOM
Imports SAPbouiCOM
Public Class Class1
'//*****************************************************************
'// At the begining of every UI API project we should first
'// establish connection with a running SBO application.
'*******************************************************************
Private WithEvents SBO_Application As SAPbouiCOM.Application
Private oForm As SAPbouiCOM.Form
Dim oButton As SAPbouiCOM.Button
Dim oOptionBtn As SAPbouiCOM.OptionBtn
Dim oCheckBox As SAPbouiCOM.CheckBox
Dim oComboBox As SAPbouiCOM.ComboBox
Dim oItem As SAPbouiCOM.Item
Dim oStatic As SAPbouiCOM.StaticText
Dim oEdittext As SAPbouiCOM.EditText
Dim oEditItem As SAPbouiCOM.EditText
Dim oFolder As SAPbouiCOM.Folder
Private oMatrix As SAPbouiCOM.Matrix
Private Matrix2 As SAPbouiCOM.Matrix
Private oLink As SAPbouiCOM.LinkedButton
Private oColumns As SAPbouiCOM.Columns
Private oColumn As SAPbouiCOM.Column
Private sPath As String
Private oDBDataSource As SAPbouiCOM.DBDataSource
Private oCompany As SAPbobsCOM.Company
Private rs As SAPbobsCOM.Recordset
Private oLineRec As SAPbobsCOM.Recordset
Private rs1 As SAPbobsCOM.Recordset
'// declaring a User data source for the "Remarks" Column
Private oUserDataSource As SAPbouiCOM.UserDataSource
Public sErrMsg As String
Public lErrCode As Long
Public lRetCode As Long
Private Sub SetApplication()
'*******************************************************************
'// Use an SboGuiApi object to establish connection
'// with the SAP Business One application and return an
'// initialized appliction object
'*******************************************************************
Dim SboGuiApi As SAPbouiCOM.SboGuiApi
Dim sConnectionString As String
SboGuiApi = New SAPbouiCOM.SboGuiApi
'// by following the steps specified above, the following
'// statment should be suficient for either development or run mode
'sConnectionString = Environment.GetCommandLineArgs.GetValue(1)
sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056" 'Environment.GetCommandLineArgs.GetValue(1)'
Try
SboGuiApi.Connect(sConnectionString)
'// connect to a running SBO Application
'// get an initialized application object
SBO_Application = SboGuiApi.GetApplication()
Catch ex As Exception
MsgBox("Make Sure That SAP Business One Application is running!!! ", MsgBoxStyle.Information)
Exit Sub
End Try
End Sub
Private Function ConnectToCompany() As Integer
'// Make sure you're not already connected.
If oCompany.Connected = True Then
oCompany.Disconnect()
End If
'// Establish the connection to the company database.
ConnectToCompany = oCompany.Connect
End Function
Private Function SetConnectionContext() As Integer
Dim sCookie As String
Dim sConnectionContext As String
' Dim lRetCode As Integer
'// First initialize the Company object
oCompany = New SAPbobsCOM.Company
'// Acquire the connection context cookie from the DI API.
sCookie = oCompany.GetContextCookie
'// Retrieve the connection context string from the UI API using the
'// acquired cookie.
sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie)
'// before setting the SBO Login Context make sure the company is not
'// connected
If oCompany.Connected = True Then
oCompany.Disconnect()
End If
'// Set the connection context information to the DI API.
SetConnectionContext = oCompany.SetSboLoginContext(sConnectionContext)
End Function
Public Sub New()
MyBase.New()
Try
SetApplication()
' Set The Connection Context
If Not SetConnectionContext() = 0 Then
SBO_Application.MessageBox("Failed setting a connection to DI API")
End ' Terminating the Add-On Application
End If
If Not ConnectToCompany() = 0 Then
SBO_Application.MessageBox("Failed connecting to the company's Data Base")
End ' Terminating the Add-On Application
End If
'SBO_Application.MessageBox("DI Connected To: " & oCompany.CompanyName)
Catch
System.Windows.Forms.MessageBox.Show("SBO application not found")
End Try
diplay_DNEWform()
End Sub
Private Sub diplay_DNEWform()
Dim oForm As SAPbouiCOM.Form
Try
oForm = SBO_Application.Forms.Item("SM_DNFM")
SBO_Application.MessageBox("Form Already Open")
Catch ex As Exception
Dim fcp As SAPbouiCOM.FormCreationParams
fcp = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)
fcp.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Fixed
fcp.FormType = "SM_DNFM"
fcp.ObjectType = "SM_DNEW"
fcp.UniqueID = "SM_DNFM"
oForm = SBO_Application.Forms.AddEx(fcp)
oForm.AutoManaged = False
DrawDNEWForm(oForm)
End Try
oForm.Visible = True
End Sub
Public Sub DrawDNEWForm(ByVal oform As SAPbouiCOM.Form)
Dim oItem As SAPbouiCOM.Item
Dim oButton As SAPbouiCOM.Button
''Form specifications
oform.Title = "define new"
oform.Left = 335 '340
oform.ClientWidth = 550 '350
oform.Top = 55
oform.ClientHeight = 200 '500
'oForm.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE
ShowAllItems(oform)
'//************************
'// Adding a OK button
'//************************
oItem = oform.Items.Add("1", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
oItem.Left = 27
oItem.Width = 65
oItem.Top = 175 '300
oItem.Height = 20
oButton = oItem.Specific
'//************************
'// Adding a Cancel button
'//***********************
oItem = oform.Items.Add("2", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
oItem.Left = 101
oItem.Width = 65
oItem.Top = 176 '300
oItem.Height = 20
oButton = oItem.Specific
End Sub
Private Sub ShowAllItems(ByVal oForm)
oDBDataSource = oForm.DataSources.DBDataSources.Add("@TESTDNEW")
Dim oEditordr As SAPbouiCOM.ComboBox
oItem = oForm.Items.Add("amtTxt", SAPbouiCOM.BoFormItemTypes.it_STATIC)
oItem.Left = 5
oItem.Width = 100
oItem.Top = 10
' oItem.AffectsFormMode = False
oItem.LinkTo = "amtVal" '"Vndval"
oStatic = oItem.Specific
oStatic.Caption = "location"
oItem = oForm.Items.Add("amtVal", SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX)
oItem.Left = 110
oItem.Width = 160
oItem.Top = 10
' oItem.LinkTo = "OrdrTxt"
oItem.AffectsFormMode = True
oEditordr = oItem.Specific
'' Adding Choose From List
oEditordr.DataBind.SetBound(True, "@TESTDNEW", "U_name")
Dim scombo As String = "Define New"
Call InitializeMCombo(oForm, scombo, "@TEST_TABLE", "<Default_Value>")
End Sub
Public Sub InitializeMCombo( _
ByRef oForm As SAPbouiCOM.Form, _
ByVal sCombo As String, _
ByVal sLinkedTable As String, _
Optional ByVal sDefaultValue As String = "" _
)
Try
oForm.Freeze(True)
Dim oCombo As SAPbouiCOM.ComboBox
oCombo = oForm.Items.Item(sCombo).Specific
Try
' Add 1-st value if database field accept NULL
oCombo.ValidValues.Add("", "")
Dim oRS As SAPbobsCOM.Recordset
oRS = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
Dim sSql As String = "SELECT Code, Name FROM [@" & sLinkedTable & "] ORDER BY 1"
oRS.DoQuery(sSql)
oRS.MoveFirst()
While oRS.EoF = False
oCombo.ValidValues.Add(oRS.Fields.Item("Code").Value, _
oRS.Fields.Item("Name").Value)
oRS.MoveNext()
End While
' Add DEFINE NEW value +++++++++++++++++++++++++++++++
' Note: Code can have length up to 8 caracters
oCombo.ValidValues.Add("Redefine", "Redefine")
If Not oRS Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS)
oRS = Nothing
End If
System.GC.Collect() 'Release the handle to the table
' Select dafault value if not null
If Not sDefaultValue.Equals("") Then
If oCombo.ValidValues.Count > 0 Then
oCombo.Select(sDefaultValue, SAPbouiCOM.BoSearchKey.psk_ByValue)
End If
Else
If oCombo.ValidValues.Count >= 1 Then
oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
End If
End If
Catch ex As Exception
' log exception
Finally
oCombo = Nothing
End Try
'
Catch ex As Exception
Finally
oForm.Freeze(False)
System.GC.Collect()
End Try
End Sub
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
oForm = SBO_Application.Forms.Item(FormUID)
If pVal.EventType = SAPbouiCOM.BoEventTypes.et_COMBO_SELECT _
And pVal.FormUID = "SM_DNFM" _
And pVal.ItemUID = "amtval" _
And pVal.BeforeAction = False _
And pVal.ItemChanged = True _
Then
SBO_Application.MessageBox("30")
Try
Try
Dim oCombo As SAPbouiCOM.ComboBox
Dim sValue As String = ""
oCombo = oForm.Items.Item("amtval").Specific
sValue = oCombo.Selected.Value
If sValue.Equals("Redefine") Then
Try
oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
oForm.Refresh()
Catch ex As Exception
'log exception
End Try
SBO_Application.Menus.Item("51207").Activate()
End If
BubbleEvent = False
Catch ex1 As Exception
' log exception
End Try
Catch ex As Exception
' log exception
End Try
End If
' Other events +++
End Sub
End Class
its not working , please check it why this is hapening.
please help me.....
Hi
1) It's not work because you need to verify InitializeCombo(...) function parameters.
If, for example, your conmbobox item on form have uid="eCmb", when you need to call function so:
Private Sub ShowAllItems(ByVal oForm)
...
'Dim sCombo As String = "Define New"
Dim sCombo As String = "eCmb"
'Call InitializeMCombo(oForm, scombo, "@TEST_TABLE", "<Default_Value>")
Call InitializeMCombo(oForm, sCombo, "@TEST_TABLE", "A")
End Sub
Function Parameters
Public Sub InitializeMCombo( _
ByRef oForm As SAPbouiCOM.Form, _ ' your form object
ByVal sCombo As String, _ ' ComboBox Item name
ByVal sLinkedTable As String, _ ' Linked Table from where you need to load values
Optional ByVal sDefaultValue As String = "" _ ' If do you want to load some default, existing in table, value.
)
Try
...
2) Use an existing example from SDK Samples, for example 07.ComplexForm
(find it in SDK_Samples_2005\COM UI\VB.NET\07.ComplexForm\2003).
Add an item COMBO_BOX and add code to catch Item Event when you select the combobox value.
Regards
Sierdna S.
Hi..
use this code
Try
ocombox = FormS.Items.Item("Combobox-ID").Specific
RS = Nothing
RS = OCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
RS.DoQuery("Select Query")
Try
If RS.EoF = False Then
For i = 1 To RS.RecordCount
ocombo.ValidValues.Add(RS.Fields.Item("U_Shiftdef").Value, i)
RS.MoveNext()
Next
'ocombo.ValidValues.Add("-9", "Define New")
End If
ocombo.ValidValues.Add("-9", "Define New")
Catch ex As Exception
SBO_Application.MessageBox(ex.Message)
End Try
Catch ex As Exception
SBO_Application.MessageBox(ex.Message)
End Try
It will work...
Regards...
Billa 2007
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Animesh,
two options.
1) give the last valid value as 'define new' and catch a combo select event for it and code to load the form where you want to define new option.
2) better one is to link this combobox field to 'No object' type of table and in that table define all the values. 'Define New' option will be there by default as the last valid value in combo box.
regards,
Binita
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Animesh ,
I don't have working code. but can outline it:
1) Add a last valid value as 'define new' in combo box.
2) catch a combo select event and check if 'Define New' is selected
3) if yes, either load the user table form what you may have created with 'No Object' type or a user defined form where you can add a new value.
ask if you still have doubts.
regards,
Binita
User | Count |
---|---|
100 | |
11 | |
10 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.