DataGrid Binding... BindingSource... trying to understand it...

DataGrid Binding... BindingSource... trying to understand it...

Old forum URL: forums.lhotka.net/forums/t/11.aspx


ward0093 posted on Friday, May 05, 2006

(This is continues from the OLD CSLA.NET Form)

I have a ROOT Object -> Child Collection -> Child Object (example: Invoice.LineItems.Item(0)); and I have three grids on my forum... Invoice Total Grid; Purchase Items (the lineItems); and Current Line Item Details.

I bind the Invoice Grid and the Purchase Items Grid to there respective objects... and the Current Item gets bound to the Collection Item at Index (0) (i.e. Invoice.LineItems.Item(0)).  I do this all through BindingSource Objects and in the beginning (before any LineItems exist in the Collection).  So this means that Invoice.LineItems.Item(0) is NOTHING....

Now... if I add a new lineitem to the collection... making Invoice.LineItems.Item(0) something... will the Line Item Details Grid update automatically without having to setup the bindings again?  Meaning... I don't change a thing after the first time i bind...???

ward0093

razorkai replied on Wednesday, May 10, 2006

I don't think this will work.  I assume you are doing something like

CurrentLineItemBindingSource.Datasource = Invoice.LineItems.Item(0);

But if like you say this equals Nothing because the grid is empty then you are not actually achieving anything with that line of code.  Off the top of my head maybe you could use either the CurrentChanged or PositionChanged events of the Line Items binding source so when the user selected a different row (or added a row) in the Line Items grid you could then rebind the Current Line Item's binding source to Item(0) or whatever they selected.  I may be talking rubbish, it is late here after all!

HTH

Copyright (c) Marimer LLC