Click here to Skip to main content
15,887,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this code that added items to list
private void GetParts(bool AllObjects)
{
    ModelObjectEnumerator ImportModel = null;
    List<Beam> parts = new List<Beam>();
    if (AllObjects)
    {
        ImportModel = MyModel.GetModelObjectSelector().GetAllObjectsWithType(ModelObject.ModelObjectEnum.BEAM);
    }
    else
    {
        TSMUI.ModelObjectSelector GetSelectedObjects = new TSMUI.ModelObjectSelector();
        ImportModel = GetSelectedObjects.GetSelectedObjects();
    }

    while (ImportModel.MoveNext())
    {
        Beam ThisBeam = ImportModel.Current as Beam;

        if (ThisBeam != null)
        {
            parts.Add(ThisBeam);

        }
    }

After that I'm supposed to iterate through all items to added to the GridView like this
for (int i = 0; i < parts.Count; i++)
{ 
        DataRow row = dt.NewRow();

        var partMark = string.Empty;
        parts[i].GetReportProperty("PART_POS", ref partMark);
        row[0] = partMark;
        row[1] = parts[i].Profile.ProfileString;
        int num = 0;
        row[2] = parts[i].GetReportProperty("MODEL_TOTAL", ref num);
        double length = 0;
        parts[i].GetReportProperty("LENGTH", ref length);
        row[3] = length;
        dt.Rows.Add(row);
}

but before I do that I want to group items using (partMark ,length ) and Sum(num ).

How can I do that?Thanks in advance.

What I have tried:

I try to use GroupBy technique but unfortunately I did not succeed
Posted
Updated 2-May-19 23:30pm

1 solution

Given you're not using SQL, I would start with a dictionary of a list of items. The key is your group by value. So you build a dictionary of lists, that's your collection of grouped by objects. Then go from there
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900