cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Gridview checkbox checked row values in sap b1

former_member416544
Participant
0 Kudos
2,603

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";
        }

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

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

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

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

former_member416544
Participant
0 Kudos

Dear Ankit,

Thank you for your prompt replay,

Could you please suggest me, how to create grid-view, with static checkbox(statically set checkbox without checking from database) value.

can you please, have a look at into my grid view code.

Thanks,

Chenna

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

Since the Grid is being populated using a SQL Query result on runtime, you need to create the CheckBox column on runtime only.

I never experienced that a Grid can have static checkbox.

Kind regards,

ANKIT CHAUHAN

SAP SME Support

former_member233854
Active Contributor
0 Kudos

Hi Chenna,

You want to get the row details or do you want to bring all check box selected? To get the row details the first answer of Ankit should help you