Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
170
Populating a second grid based on the first grid's active row
posted

I have two WinGrids on a Windows form.  It is similar to Customers and Orders grids.  When I select a row (activate) from the customers grid, I want to populate the Orders grid based on the Customer Id from the Customers grid.  I am not sure how to find the currently active row on the customer grid.  "AfterRowActivate" does not seem to contain any information about the row.  I am sure this is simple enough to do.  But don't know how.  A pointer to some sample code is highly appreciated.

 By the way, I am using NetAdvantage 2008.1.

Thank you

Babu.

Parents
No Data
Reply
  • 17259
    Offline posted

    You can get the active row by using the grid.ActiveRow property any time, but I think you should solve it not through the grid. Actually this is a simple master-detail issue and you can find many samples for that.

    I do it like that:

    1. Load Customers and Orders. You can use lazy load that loads Orders only by demand, like Linq to Sql does.

    2. Create a BindingSource and set the Customers as its data source. Set the binding source as the Customers grid data source.

    3. Create a BindingSource and set the Customers as its data source. Set the DataMember property as the name of the property in the customers that used to get its orders, like "CustomerOrders". Attach this Binding source as the data source of the orders grid.

    That's it. When you select a customer it'll automatically show its orders. You can use the designer of VS for that. Open the Data menu and select "Show Data Sources" and add a new Data Source to your project. What you do from here depends how you bring your data.

Children