Programmatic Manupulation of DataGridView
I am writing a Copy/Paste system for my application which uses DataGridView controls.
We have a DataGridView with an underlying datasource. This Source implements IBindingLIst, which as you know, when the grid is set to "AllowUserToAddRows" will
automatically call the IBindingList.AddNew() method on the datasource and add a new row when the user navigates the to "new row" item in the grid (indicated by the * in the Row header).
2 problems:
First - I cannot seem to execute the same functionality from the Grid via code. So the user selects a set of cells, and ties to "Paste" the data, if the data is more than the number of rows added to the grid, I cannot request through the Grid to add a new row, like the user can by just clicking in the new row cells.
Second -
So, instead i went to typecast the DataSource as an IBindingList and followed a similar procedure for updating the data. I would verify the currently selected row is or is not the "IsNewRow" indicator for being the "User added row". If it is an existing row with a DataBoundItem, i woudl update it with the pasted information from the Clipboard.
However, when it is the new row, I woudl execute IBindingList.AddNew() and update the object returned directly. To this I get all sorts of problems.
The "New row" as created by the DataGridView is not committed to the underlying DataSource at this time and throws exceptions. I have no way to tell the grid "STOP THE CURRENT ADD OF A NEW ROW"
I want the user to be able to type directly in the grid to add a new row, but I also want the ability to "Select a Cell on the 'new row'" and paste data into it.
How do I achieve this?
Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner