I created a Linq to SQL class from an mdf.
I created a DataSource from that object.
I created a WinForm and dragged fields from my DataSource, including the built-in Navigator.
My form is for a table called "Tickets"
Each ticket has a Foreign Key to the Batch table. The idea is that a batch of tickets are created in one session, so each ticket has a BatchID.
So, here's my problem...
When I create a new record (by clicking the + on the NavBar), I need to assign the BatchID to the Ticket, and display it on the form.
I cannot figure out a way to do that.
I bound the controls on my WinForm by dragging fields from the DataSource, which is based on the LinqToSql object.
I've placed code assign the value to the textbox in the AddingNew event of the BindingSource, but apparently, that event runs before the new record is created (or the form is updates, or something) and thus the value gets reset to null.
I've tried setting a flag in the AddingNew event that indicates we're creating a new record and then set the BatchID in the CurrentChanged event when that flag is true.
That works -- until I change the first value in the form. Then the BatchID textbox clears.
I've read that there's a way to set the field's Default Value (each time a new batch is created) but I can't figure out how to do it.
Do you have any suggestions on any way to set my BatchID when a new ticket record is created?
From my searches, here on EE, it seems the primary recommendation is to set the value in the dataset, but I can't figure out what that is because my BindingSource's DataSource is the LinqToSql class. I don't see where a dataset is created.