Home Forums WinForms controls Xceed Grid for WinForms How to get the parent row’s data object in a DetailGrid?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #12985 |

    If a grid is bound to a custom object collection (not a dataset), is there any way for a detailgrid within that grid to retrieve the object that belongs to the parent row?

    For example,

    I have a collection of customer objects. Each customer object has a collection of invoices:
    – inv1
    – inv2
    – inv1
    – inv2
    – inv1

    I can bind the customer object collection to a grid and it all works fine (just by setting the grid’s DataSource property to the customer collection object).

    I then want to add a detail grid which when expanded binds to the invoices collection for that customer.

    When I expand cust2, for example, what’s the best way to access the invoice collection for cust2? It would be ideal if there was some way to access the ‘cust’ object directly. Or can I get the index of the collection reference and then reference the DataSource on the parent grid to get the cust object?


    Imported from legacy forums. Posted by Jamie (had 2049 views)

    User (Old forums)
    Post count: 23064

    Here’s a summarised version of the solution that Tech Support gave me:

    When defining the detail grid, set the following properties. This assumes that it is the ‘Invoices’ property on each Customer object that holds the collection of Invoices.

    MyDetailGrid.DataSource = null;
    MyDetailGrid.DataMember = “Invoices”;

    If you want to load the detail on demand (ie. only when you expand the customer row):
    1. subscribe to the DetailGrid’s CollapsedChanged event
    2. set SynchronizeDetailGrids = false on the DetailGrid
    3. bind to the collection in the CollapsedChanged event as follows:

    private void DetailGridTemplate_CollapsedChanged( object sender, EventArgs e )
    if( !( ( DetailGrid ) sender ).Collapsed )
    ( ( DetailGrid ) sender ).SetDataBinding( null, “Invoices” );


    Imported from legacy forums. Posted by Jamie (had 3219 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.