Newbie seeking advice, 3-level hierarchy, display level 1 & 3, don't display level 2

Posted by: jon-larson on 8 September 2017, 1:40 pm EST

  • Posted 8 September 2017, 1:40 pm EST

    Having just begun to glimpse the power and flexibility of fpspread, I'm sure there are a number of ways to skin this particular cat.  BUT - lacking even the most rudimentary knowledge of each/every capability of fpspread, I'm uncertain ast to the best (meaning least amount of coding to achieve the desired result) approach.  So I'm inviting any (and that means ANY) comment that might lead me to the optimum solution.

    I hope the following is a reasonable analogy for the project:

    Acme Inc. manufactures a number of PRODUCTS including Doo-Hickeys, Gadgets, Thing-A-Ma-Jigs, and Widgets.  Each of those products is assembled from assembled component MODULES including power module, cooling module, viewer module, mobility module, heating module, analyzer module, printer module, etc.  Any given module may be used in assembly of one or more products - thus the product-module relationship is one-to-many.  Of course, not all modules are used in any given product.

    Each module is assembled from discrete COMPONENTS, including Resistor1, Resistor2, Resistor3, PrintHead1, PrintHead2, PrintHead3, CRT1, CRT2, CRT3, etc.  There are an unlimited number of discrete components within each type.  The module-component relationship is therefore essentially many-to-many.

    All data is, of course, contained in a database.  Tables: Product, Modules, Components as follows:
    Products
             ---> Modules
                          ---> Components


    Now, as to the fpread layout and desired functionality:

    The ParentRow will display the PRODUCT, ie: Doo-Hickey, Gadget, Thing-A-Ma-Jig, and Widget and will be expandable.

    Upon expanding the ParentRow for any give PRODUCT, I wish to have the grid display the discrete COMPONENT list.  I do NOT wish to see anything from the MODULE list.

    In its "natural" layout, the grid seems to want to display something like this (with headers at each level):

    Widget
    ---> PowerModule1    $45.00  120VAC
    --------> Resistor1
    --------> Resistor5
    ---> PrinterModule3  $30.00
    --------> PrintHead2
    --------> Inker7
    ---> CoolingModule4  $80.00
    --------> Fan6
    --------> Evaporator2

    BUT WHAT I WANT TO DISPLAY IS (with only one header for the COMPONENTS list):

    Widget
    --------> Resistor1
    --------> Resistor5
    --------> PrintHead2
    --------> Inker7
    --------> Fan6
    --------> Evaporator2


    How might I most easily achieve this?

  • Replied 8 September 2017, 1:40 pm EST

    Hello,


    Try code like the following in the ChildViewCreated event of the Spread. You would need to change the RelationName check to the name of the relation you use between the parent and first child.


    Private Sub FpSpread1_ChildViewCreated(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.ChildViewCreatedEventArgs) Handles FpSpread1.ChildViewCreated


    If e.SheetView.ParentRelationName = "relA" Then


    For i As Integer = 0 To e.SheetView.RowCount - 1


    e.SheetView.ExpandRow(i, True)


    e.SheetView.Rows(i).Height = 1


    e.SheetView.ColumnHeaderVisible = False


    Next


    End If


    End Sub

  • Replied 8 September 2017, 1:40 pm EST

    Your solution works - in a fashion - but falls somewhat short of the
    desired result.  The code segment you provided does in fact disable
    display of the level-2 (Module) data.  However, for each Component
    listed, each component has its own header and horizontal scrollbar. 
    Sort of like this:

    Component Header

    Resistor1


    Component Header


    Resistor2



     


    Where the goal is to achieve a display sort of like:


    Component Header


    Resistor1


    Resistor2


     Thus eliminating the redundant Component Header. 

    I'd been looking at a custom sheet... seemed quite a bit of tedious coding, so I was hoping for a more efficient solution.

     

    Thoughts?

  • Replied 8 September 2017, 1:40 pm EST

    Hello,


    There is not any easy way to do what you want unless there is a way to create your DataSet with just two tables and relate the first level to the third level without the middle table. I do not think you would be able to do this. Otherwise you would need to write your own SheetView object that gets values from the correct tables and sets changes back in. The custom SheetView would be a lot of tedious coding as you have seen.

  • Replied 8 September 2017, 1:40 pm EST

    Thank you, Scott.  I was afraid a custom SheetView might be the only real solution.

     

    Can you tell me.... which of the VB.net examples do you feel would be most helpful in guiding my way in implementing this custom SheetView?

  • Replied 8 September 2017, 1:40 pm EST

    Hello,


    The following thread has a sample project that has C# and VB code for implementing this.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels