Hi,
Senario: I have a grid which displays the queue of the patients who visits an hospital. Each time on adding a patient to the queue the grid losts it position and refreshing the datasource to update the queue. I know that it was happening because of each time I add a record I'm using the below statements to update the grid.
QueueMaster queueMaster = new QueueMaster();
ugQueue.DataSource = queueMaster.GetTodaysQueue();
ugQueue.Refresh();
these statements will run every time after adding a new record to the database.
how can i eliminate the situation so that, the position of the grid remains stable even the was datasource updated?
Any help will be appriciated.
With regards,
SreeRam.
1. Don't reassign DataSource. Don't do this:
msrs_it said:ugQueue.DataSource = queueMaster.GetTodaysQueue();
You can call something like Merge if queueMaster.GetTodaysQueue(); returs a datatable or a dataset. Or don't throw away the objects in QueueMaster when updating from database. Make QueueMaster a singleton and let it add new records into existing data (for instance, dataset/datatable) instead of recreating everything from scratch
2. You can remember the position of datagrid and reset it after you rebind the data. But then such things as filters, sorting, groups etc. will be lost. So, the first solution is much more preferable.