New row in a cascaded DataGridView RRS feed

  • Question

  • Refering to Beth Massi's blog on the subtlties of cascading datagridViews: -

    I have Customer and Order DataGridViews with the DGVOrder datasource being based on customer.

    I am having trouble adding a new Order if the Customer doesn't already have an order assigned to it.

    The problem is caused by the fact that Order.CustomerID is only auto generated when Order table has data in it.

    Could anyone tell me how to get the Order.CustomerID to auto populate correctly, and elegantly, when there are no entries in the Order table?

    My binding code is as follows: -

    DC = New
    DC.Log = writer
    CustomerList = (From
     s In
     DC.Customer Order
    CustomerBindingSource.DataSource = CustomerList
    CustomerDataGridView.Datasource = CustomerBindingSource
    OrdersDataGridView.DataSource = CustomerBindingSource
    OrdersDataGridView.DataMember = "Orders"
    Many Thanks

    • Edited by trager Friday, November 20, 2009 9:29 PM spelling
    Friday, November 20, 2009 9:28 PM


  • I found the problem.

    Basically I was was validating the existence of the CustomerID in the Validating event of the Orders DataGridView and that event fires before the DGV gets the chance to assign the CustomerID. 

    Feeling a bit of Numpty.

    Ho Hum.
    • Marked as answer by trager Saturday, November 21, 2009 11:36 AM
    Saturday, November 21, 2009 11:36 AM