I use a DataGridView to display rows from PostgreSQL, which works fine. Now whnt I want to implement is an editor that can add, edit and remove rows from that DataGridView. To do so, I have created event handlers to handle these events. In the handlers, I will insert, update or delete the row in my PostgreSQL database.
dgOrderLines.RowsAdded +=
new DataGridViewRowsAddedEventHandler(dgOrderLines_RowsAdded);
dgOrderLines.RowsRemoved +=
new DataGridViewRowsRemovedEventHandler(dgOrderLines_RowsRemoved);
dgOrderLines.CellEndEdit +=
new DataGridViewCellEventHandler(dgOrderLines_CellEndEdit);
However, if I run this code, I see events being fired when I first populate the DataGridView like this:
dgOrderLines.DataSource = Program.DB.GetView("someview");
(Program.DB.GetView returns a DataTable.)
Now, if I would be to implement the event handlers, I will be adding and removing records in my database, every time I load my DatagridView. Is there a way to prevent that?