cancel
Showing results for 
Search instead for 
Did you mean: 

chaos in grid with rows which are collapsed and expanded

Former Member
0 Kudos

I have problem with collapse and expand functionality. I've added some rows and set on grid collapseLevel = 1.

Everything is displayed correctly and grouped as I expected but when i want to catch a row data I get data wich is incorrect. The problem is that when the data is grouped is ordered with a groups and clicking any row gives me other rows data.

For example when I click row 3 I get the data from row 2.

 Grid EqElemGrd = form.Items.Item(PhysicalPropertyFormulaForm.Controls.EquationElements.Grid).Specific;
            DataTable EqElemData = form.DataSources.DataTables.Item(PhysicalPropertyFormulaForm.DataSources.EquationElements.DataTable);
            EqElemData.Rows.Clear();


            Dictionary<string, string> functions = new Dictionary<string, string>();
            functions.Add("ABS(x)", "Returns the absolute value of x.");
            functions.Add("ACOS(x)", "Returns the arc cosine of x, in radians.");
            functions.Add("ASIN(x)", "Returns the arc sine ofx, in radians.");
            functions.Add("ATAN2(x; y)", "Returns ATAN(y/x) taking signs of x and y into account.");
            functions.Add("ATAN(x)", "Returns the arc tangent of x, in radians.");
            functions.Add("CEILING(x; signif)", "Returns the nearest multiple of signif");

            int i = 0;


            foreach (var func in functions)
            {


                EqElemData.Rows.Add();
                EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Type, i, "Function");
                EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Code, i, func.Key);
                EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Description, i, func.Value);
                i++;


            }




            EqElemData.Rows.Add();
            EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Type, i, "Global");
            EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Code, i, "TW");
            EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Description, i, "Total Formula Weight");
            i++;
            EqElemData.Rows.Add();
            EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Type, i, "Global");
            EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Code, i, "TV");
            EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Description, i, "Total Formula Volume");
            i++;


            QueryManager qm = new QueryManager();
            qm.SimpleTableName = "@CT_PF_OIPR";
            qm.SetSimpleWhereFields("U_FrlaPrp");
            qm.SetSimpleResultFields("U_FrlaType", "U_PrpCode", "U_PrpName");


            using (var result = qm.ExecuteSimpleParameters("", "Y"))
            {
                for (int k = 0; k < result.RecordCount; k++)
                {
                    EqElemData.Rows.Add();
                    string U_PrpCode = result.Fields.Item("U_PrpCode").Value;
                    string U_PrpName = result.Fields.Item("U_PrpName").Value;
                    string U_FrlaType = result.Fields.Item("U_FrlaType").Value;
                    EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Type, k + i, U_FrlaType);
                    EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Code, k + i, U_PrpCode);
                    EqElemData.SetValue(PhysicalPropertyFormulaForm.DataSources.EquationElements.Columns.Description, k + i, U_PrpName);


                    result.MoveNext();
                }
            }


            EqElemGrd.CollapseLevel = 1;
            EqElemGrd.Rows.CollapseAll();
former_member233854
Active Contributor
0 Kudos

Could you share the code you use to get the data from the grid? As far as I understood this code is showing how you are filling the grid

Former Member
0 Kudos
public override void OnDoubleClickAfter(string FormUID, ref PItemEvent itemEvent)
        {


            if (itemEvent.ItemUID == PhysicalPropertyFormulaForm.Controls.EquationElements.Grid && itemEvent.Row != -1)
            {
                
                Form form = itemEvent.CurrentForm;
                Grid ElementsBodyGrd = form.Items.Item(PhysicalPropertyFormulaForm.Controls.EquationElements.Grid).Specific;
              
                EditText EqBody = form.Items.Item(PhysicalPropertyFormulaForm.Controls.EquationBodyEditText).Specific;




                EqBody.Value += ElementsBodyGrd.DataTable.GetValue(PhysicalPropertyFormulaForm.Controls.EquationElements.Columns.Code, itemEvent.Row);


            }
        }

Accepted Solutions (1)

Accepted Solutions (1)

former_member233854
Active Contributor
0 Kudos

Hi,

The problem happened because when you collapse the grid, the rows are not the same as the datatable it is linked to, so you can use GetDataTableRowIndex to get the right row

EqBody.Value += ElementsBodyGrd.DataTable.GetValue(PhysicalPropertyFormulaForm.Controls.EquationElements.Columns.Code, ElementsBodyGrd.GetDataTableRowIndex(itemEvent.Row));
Former Member
0 Kudos

Thanks for your help. I have additional problem. When I update on the form collapsed and expand functionality is missing. Everything is viewed as there is no collapselevel = 1. Have you got any idea how to improve it. I want to have grouped view after update. I've checked and initialize events like updateafter, onformstatuschanged, onformloadafter.

former_member233854
Active Contributor
0 Kudos

I believe it depends on how you are updating this. Probably your data is being reloaded.

Former Member
0 Kudos

This describes and resolves my issue:

https://archive.sap.com/discussions/thread/1692725#

Thanks once more for your effort.

Have a good day 🙂

Answers (0)