0

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?

1 Answer 1

2

Found it.

When setting the DataSource before setting the event handlers, they do not get called.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.