Hello there. What I am breaking my teeth on right now is this: I have a simple database application that shows data using a datagridview. This control is bound to a DataView (so I can apply filtering). The Dataview is bound to a DataSet which is then filled from a DataAdapter using Fill method.
The application connects to a remote computer and there can be several clients doing the same - adding, editing or deleting records. To keep track of changes, I need to refresh (or re-read) the data from time to time, so each client keeps track of recent changes. Now I do it this way:
DataSet.Tables("MyTable").Rows.Clear
DataAdapter.Fill(DataSet, "MyTable")
If I don´t clear the DataSet´s table contents, the datagrid would show only current and newly added records, but also keep displaying deleted records.
Now to the point: the problem is that each time the datagrid is refreshed, it is basically cleared and filled again, loosing the information of currently selected row. After refreshing, the first row always gets selected. My question is: how not to loose the currently selected row?
Now I use these steps to partially overcome this issue:
- get the value (IDa) in the column called "ID" (distinct value) on currently selected row
- perform the refresh
- loop through the displayed rows: if ID of a row equals IDa then select that row
It does the job, but it also scrolls the selected row out of view and I am afraid that it won´t be much effective when there are many rows in the future.
Is there a simpler way?
Thanks
The application connects to a remote computer and there can be several clients doing the same - adding, editing or deleting records. To keep track of changes, I need to refresh (or re-read) the data from time to time, so each client keeps track of recent changes. Now I do it this way:
DataSet.Tables("MyTable").Rows.Clear
DataAdapter.Fill(DataSet, "MyTable")
If I don´t clear the DataSet´s table contents, the datagrid would show only current and newly added records, but also keep displaying deleted records.
Now to the point: the problem is that each time the datagrid is refreshed, it is basically cleared and filled again, loosing the information of currently selected row. After refreshing, the first row always gets selected. My question is: how not to loose the currently selected row?
Now I use these steps to partially overcome this issue:
- get the value (IDa) in the column called "ID" (distinct value) on currently selected row
- perform the refresh
- loop through the displayed rows: if ID of a row equals IDa then select that row
It does the job, but it also scrolls the selected row out of view and I am afraid that it won´t be much effective when there are many rows in the future.
Is there a simpler way?
Thanks