cancel
Showing results for 
Search instead for 
Did you mean: 

how to bind a combobox with an recorset in c#

Former Member
0 Kudos

hey guys, im really new i would like to bind a combobox with payment terms, i use this code but didn't work, can anybody help me?

thank you

SAPbobsCOM.Recordset orec = null; orec = ((SAPbobsCOM.Recordset)(oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset))); orec.DoQuery("select GroupNum,PymntGroup from OCTG"); while (!orec.EoF) { ComboBox1.ValidValues.Add(orec.Fields.Item("GroupNum").Value.ToString(), orec.Fields.Item("PymntGroup").Value.ToString()); orec.MoveNext();

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member416544
Participant
0 Kudos

Hi,

private void BindComboBox(SAPbouiCOM.ComboBox oCombo)
        {
            try
            {
                string vDoQuery_string = null;
                int vRecordsetIndex_long;
                int vRecordsetCount_long;

                SAPbobsCOM.Recordset oRecordset = null;
                oRecordset = ((SAPbobsCOM.Recordset)(ServiceLocator.SboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)));
                vDoQuery_string = "SELECT CardCode,CardName FROM OCRD";
                oRecordset.DoQuery(vDoQuery_string);
                vRecordsetCount_long = oRecordset.RecordCount;
                oRecordset.MoveFirst();
                //oCombo.ValidValues.Add("0", "-- Select CardCode --");// Add the default value
                for (vRecordsetIndex_long = 0; vRecordsetIndex_long <= vRecordsetCount_long - 1; vRecordsetIndex_long++)
                {
                    oCombo.ValidValues.Add(System.Convert.ToString(oRecordset.Fields.Item(1).Value), System.Convert.ToString(oRecordset.Fields.Item(0).Value));
                    oRecordset.MoveNext();
                }
                oCombo.Select(2, BoSearchKey.psk_Index);
                oRecordset = null;
                System.GC.Collect();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                //oApplication.MessageBox("Add-On Error: Error-3256 " + Error.Message, 1, "Ok", "", ""); // My Error Code
            }
        }

You can call the above 'BindComboBox' method into your combox.

Regards,

Chenna.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

Check whether it does help or not?

SAPbobsCOM.Recordset oRecSet = default(SAPbobsCOM.Recordset);
            SAPbouiCOM.ButtonCombo oCombo = default(SAPbouiCOM.ButtonCombo);
            try
            {
                oCombo = (SAPbouiCOM.ButtonCombo)this.m_SBO_Form.Items.Item(enControlName.btnCombo).Specific;
                oRecSet = (Recordset)this.SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                oRecSet.DoQuery("SELECT Name FROM [@CopyToValuesMaterialRequest] order by Code Asc");
                if (oCombo.ValidValues.Count > 0)
                {
                    for (int i = 0; i <= oCombo.ValidValues.Count; i++)
                    {
                        oCombo.ValidValues.Remove(i, SAPbouiCOM.BoSearchKey.psk_Index);
                    }
                }
                oCombo.ValidValues.Add("", "");
                if (oRecSet.RecordCount > 0)
                {
                    while (oRecSet.EoF == false)
                    {
                        oCombo.ValidValues.Add(oRecSet.Fields.Item(0).Value.ToString().Trim(), "");
                        oRecSet.MoveNext();
                    }
                }
            }
            catch (Exception ex)
            {
                this.SBO_Application.SetStatusBarMessage(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, true);
            }

Kind regards,

ANKIT CHAUHAN

SAP SME Support