Part Lists programatically

Top  Previous  Next

Here you get an existing Part List and add a row to it:

 

       // There can be many part lists in a single sheet, get hold of the list of lists...

       CComPtr<PartsLists> pPartsLists;

       hRes = pSheet->get_PartsLists(&pPartsLists);

 

       // Make a 2d point to specify the top left corner of the partslist...

       CComPtr<TransientGeometry> pTransGeom = GetTransGeomPtr () ;

       CComPtr<Point2d> pListPos; // Create a 2d point

 

       // Place top left of part list in the center of the sheet...

       pTrGeom->CreatePoint2d(SheetWidth/2.0,SheetWidth/2.0,&pListPos);   

 

       // To create a part list you add it to the list of part lists....

       CComPtr<PartsList> MyPartList;

       CComVariant varNumNum(kNumericNumbering);

       hRes = pPartsLists->Add(pBaseView1, pListPos, kFirstLevelComponents, varNumNum, 1, VARIANT_FALSE, &MyPartList);

 

       // A part list is in essence a set of rows...

       PartsListRowsPtr pRows = MyPartList->GetPartsListRows();

       long iNumRows = pRows->Count;

 

       // Add a new row.

       // This new row will have the same number of columns as existing rows

       CComPtr<PartsListRow> pNewRow;

       hRes = pRows->Add(iNumRows,  // Relative to which existing row we insert the new one?

                         VARIANT_FALSE, // FALSE means insert after the exsiting roe

                         &pNewRow); // Returned new row

       long iNumCols;

       pNewRow->get_Count(&iNumCols);

       if (iNumCols >= 4) {

           // Test adding text into col 3

           // Col1 is id, 2 is quantity, they have default values 3 and 4 you fill out

           CComPtr<PartsListCell> pCell;

           CComVariant ColNum(3);

           pNewRow->get_Item(ColNum, &pCell);

           CComBSTR Hello(L"Hello you");

           pCell->put_Value(Hello);

       }

 

 

So you have to get hold of the cell and then modify it.

 

PartList

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)