2022-03-15

What is the best way to gather data from database based the cell selection of a DataGridView (C# .Net Windows Application)

I have a DataGridView (C# .Net windows application) filled with more than 1000 rows also each row has a unique row id as well. If I select multiple cells then take the subdata from another table and display it in the same form.

I wrote the code inside the CellEnter event so whenever I select a cell, the event fires and takes the subdata from the database based on the unique id.

For Instance I have two tables: Table_Orders (OrderID primary key) ,Table_ShipmentDetails (OrderID Foreign Key). The DataGridView filled with Orders.Whenever i select cell,should display the shipment details.If i select multiple cells then find the OrderIDs and fetch the shipment details and compare them, if it is same then display else leave the information as blank

When i use CellEnter event my issues are

  1. If I select two cells in the same row, the event fires and fetches the same data two times from the database.

  2. If I select many cells together either with the mouse down or key down and with a slow connection, then the form will freeze and end up with restarting the program.

How can I avoid fetching the same data multiple times?

I tried to gather all the OrderIDs when entering the cell but couldn't find how to identify when the selection is completed for fetching the data together for all selected OrderIDs.

Can anyone help me to suggest an effective way to fix this issue?



No comments:

Post a Comment