Skip to Content

How to get Gridview checkbox checked row values in sap b1

Hi,

I have created a form with custom grid view, with bind a data into grid dynamically. Now, I'm trying to get the details of checkbox checked rows values into the grid-view.

It means, while clicking of the Create SalesOrder button, i want to get the details of checkbox checked items(ClgCode 1,9) records.

Can you please someone suggest me sample code, for get checkbox checked row details in grid-view.

This is my code for create grid-view.

 public void GridSample()
        {
            SetApplication();
            // LoadFromXML("TabOrder.srf")
            CreateForm();
            //  Get the added form object by using the form's UID
            oForm = SBO_Application.Forms.Item("frmGrid");
            //  Show the form
            oForm.Visible = true;
        }

        private void CreateForm()
        {

            SAPbouiCOM.FormCreationParams CP = null;
            SAPbouiCOM.StaticText oStat = null;
            SAPbouiCOM.Button oBtn = null;
            SAPbouiCOM.OptionBtn oOpt = null;
            SAPbouiCOM.CheckBox chkbox = null;
            SAPbouiCOM.CheckBoxColumn chkboxclm = null;
            //SAPbouiCOM.Item oItemBP = null, oItem = null;
            CP = ((SAPbouiCOM.FormCreationParams)(SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)));
            CP.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Sizable;
            CP.FormType = "SAMPLE";
            CP.UniqueID = "frmGrid";

            oForm = SBO_Application.Forms.AddEx(CP);
            //  Set form width and height
            oForm.Left = 800;
            oForm.Top = 140;
            oForm.Height = 450;
            oForm.Width = 770;
            oForm.Title = "Formpak Produce Samples";
            //  Add a Grid item to the form
            oItem = oForm.Items.Add("SalOrdGrid", SAPbouiCOM.BoFormItemTypes.it_GRID);
            //  Set the grid dimentions and position
            oItem.Left = 20;
            oItem.Top = 40;
            oItem.Width = 720;
            oItem.Height = 350;

            //  Set the grid data
            oGrid = ((SAPbouiCOM.Grid)(oItem.Specific));
            oForm.DataSources.DataTables.Add("SalesDataTable");
            oForm.DataSources.DataTables.Item(0).ExecuteQuery("SELECT ClgCode , CardCode as '#Check items', CardCode, Notes as 'Subject',U_WID_Project as 'Project',U_WID_fptaskcode as 'Task Code',U_WID_ItemCode as 'ItemCode',U_WID_ItemName as 'ItemName',U_WID_Qty as 'Qty',U_WID_MofUnit as 'M of Unit',U_WID_packqty as 'No of Packagage',U_WID_dosage as 'Dosage'  FROM OCLG ORDER BY ClgCode ASC");
            oGrid.DataTable = oForm.DataSources.DataTables.Item("SalesDataTable");

            //  Set columns size
            oGrid.Columns.Item(0).Editable = false;
            oGrid.Columns.Item(1).Type = SAPbouiCOM.BoGridColumnType.gct_CheckBox;



            oItem = oForm.Items.Add("2", SAPbouiCOM.BoFormItemTypes.it_BUTTON);
            oItem.Left = 20;
            oItem.Top = 390;
            //oItem.Width = 90;
            oItem.AffectsFormMode = false;
            oBtn = ((SAPbouiCOM.Button)(oItem.Specific));
            oBtn.Caption = "Cancel";

            oItem = oForm.Items.Add("btnCreOrd", SAPbouiCOM.BoFormItemTypes.it_BUTTON);
            oItem.Left = 630;
            oItem.Top = 390;
            oItem.Width = 90;
            oItem.AffectsFormMode = false;
            oBtn = ((SAPbouiCOM.Button)(oItem.Specific));
            oBtn.Caption = "Create SalesOrder";
        }
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Sep 07, 2017 at 01:17 AM

    Hi,

    If it is a Grid which is populated using a query, it should be used something as below:

    for (int k = 0; k <= oGrid.Rows.Count - 1; k++)
    {
        string IsSelected = oGrid.DataTable.GetValue("ColumnName", k).ToString();
        if (IsSelected == "Y")
        {
    	//Do your operation.
        }
    }
    

    Kind regards,

    ANKIT CHAUHAN

    SAP SME Support

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 07, 2017 at 01:22 AM

    If it a Matrix, it should be used something as below:

    for (int i = 1; i <= oMatrix.RowCount; i++)
    {
        SAPbouiCOM.CheckBox oChkSelect = (SAPbouiCOM.CheckBox)oMatrix.Columns.Item("colSelect").Cells.Item(i).Specific;
        if (oChkSelect.Checked == true)
        {
    	// Do your operation.
        }
    }
    

    Kind regards,

    ANKIT CHAUHAN

    SAP SME Support

    Add comment
    10|10000 characters needed characters exceeded