cancel
Showing results for 
Search instead for 
Did you mean: 

ComboBox - DataBind

Former Member
0 Kudos

Hi,

i will bind a DataTable ("OHEM") Column (firstName) on a Combobox.

I get no Error, but the Combobox is empty.

oForm.DataSources.DBDataSources.Add("OHEM");
            oItem = oForm.Items.Add("nAG_mitarb", SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX);
            oItem.Top = 50;
            oItem.Left = 380;
            oItem.Width = 80;
            oCombobox = (SAPbouiCOM.ComboBox)oItem.Specific;
            oCombobox.DataBind.SetBound(true, "OHEM", "firstName");

What´s wrong?

Thank u!

Regards

Dhomas

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dhomas,

Try This..........


 SAPbobsCOM.Recordset orec = null; 
orec= ( ( SAPbobsCOM.Recordset )( oCompany.GetBusinessObject( SAPbobsCOM.BoObjectTypes.BoRecordset ) ) ); 

Thanks

Shafi

Former Member
0 Kudos

it Works !

THANKS Shafi

Answers (2)

Answers (2)

Former Member
0 Kudos

Is there any way other than a loop to assign the datasource to a combobox

as this procedure is taking a long time when there's a lot of entries ?

Former Member
0 Kudos

Hi Dhomas,

To Load values into the combobox

Try This.......

in vb.net



   odbdatasource = oform.DataSources.DBDataSources.Add("ohem")
            oitm = oform.Items.Add("cmb", SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX)
            oitm.Left = 30
            oitm.Top = 2
            ocmb = oitm.Specific
            ocmb.DataBind.SetBound(True, "ohem", "firstname")
            Dim orec As SAPbobsCOM.Recordset
            orec = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            orec.DoQuery("select firstname from ohem")
            For i As Integer = 0 To ocmb.ValidValues.Count - 1
                ocmb.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index)
            Next
            While orec.EoF = False
                ocmb.ValidValues.Add(orec.Fields.Item(0).Value, orec.Fields.Item(0).Value)
                orec.MoveNext()
            End While

in C#.net


odbdatasource = oform.DataSources.DBDataSources.Add("ohem");
oitm = oform.Items.Add("cmb", SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX);
oitm.Left = 30;
oitm.Top = 2;
ocombobox = oitm.Specific;
ocombobox.DataBind.SetBound(true, "ohem", "firstname");
SAPbobsCOM.Recordset orec = default(SAPbobsCOM.Recordset);
orec = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
orec.DoQuery("select firstname from ohem");
for (int i = 0; i <= ocmb.ValidValues.Count - 1; i++) {
	ocombobox.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index);
}
while (orec.EoF == false) {
	ocombobox.ValidValues.Add(orec.Fields.Item(0).Value, orec.Fields.Item(0).Value);
	orec.MoveNext();
}

Thanks

Shafi

Edited by: shafi_sunshine on Aug 17, 2011 9:48 AM

Former Member
0 Kudos

Hi shafi,

thank u but now i get a NullReferenceException on this line

 
orec =(SAPbobsCOM.Recordset)con.nFirma.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

Here is my Code :

datasource=oForm.DataSources.DBDataSources.Add("OHEM");
            oItem = oForm.Items.Add("nAG_mitarb", SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX);
            oItem.Top = 50;
            oItem.Left = 380;
            oItem.Width = 80;
            oCombobox = (SAPbouiCOM.ComboBox)oItem.Specific;
            oCombobox.DataBind.SetBound(true, "OHEM", "firstname");
            SAPbobsCOM.Recordset orec = default(SAPbobsCOM.Recordset);
            orec = (SAPbobsCOM.Recordset)con.nFirma.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            orec.DoQuery("Select firstname from ohem");
            for (int i = 0; i <= oCombobox.ValidValues.Count - 1; i++)
            {
                oCombobox.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index);

            }
            while (orec.EoF == false)
            {
                oCombobox.ValidValues.Add(orec.Fields.Item(0).Value.ToString(), orec.Fields.Item(0).Value.ToString());
                orec.MoveNext();
            }

Edited by: Dhomas on Aug 17, 2011 10:45 AM