I have a DataGridView
bound to a LINQ to SQL query expression. I want it to be editable for updates, but for inserts I want users to use separate controls below the grid (textboxes, date pickers, etc - currently not bound to anything). I have an "Add" button that creates an object of the linq to sql entity class based on the values in the controls, and then calls InsertOnSubmit()
. When I later call SubmitChanges()
, any updates from the grid, and any objects added are all correctly persisted to the database.
My problem is that any new objects are not added to the grid, before or after the call to SubmitChanges()
. I would like new objects to be added to the grid as soon as they are created. Also, I only want the controls below the grid to be used for inserting new records, not editing existing records, so I don't think they should be bound to the data source...What is the best way to make this happen?
I did try simply re-setting the DataSource
for the grid (ie dataGridView.DataSource = db.<TableName>
, which works, but is clumsy because it scrolls to the top of the grid again - I'm sure a better method exists.
(Pls excuse the n00b question, I'm very new to all this .net stuff :P)