We show our data on datagrids tied to a dataset, which, in turn, comes from the Progress database on the server. During processing, we need to make changes to the data set and update it from the server. So far so good, good and no problem.
The problem is that when we return with the new data, we want the datagrid selection to remain on the same row as before. We managed the following code:
int iPostingPos = dgridPostings.CurrentRow.Index; // process data on server dataContTranMatch.RunBoProcedure(dataContTranMatch.BoProcedure, transactionMatchingDataSet); // Reload Data LoadData(); if (iPostingPos > ttPOSTingsRowBindingSource.Count) { iPostingPos = ttPOSTingsRowBindingSource.Count; } if (ttPOSTingsRowBindingSource.Count > 0) { ttPOSTingsRowBindingSource.Position = iPostingPos; dgridPostings.Rows[iPostingPos].Selected = true; }
This works, but we get a highlighted line jumping on the screen, which is very annoying for users.
For example, if you select line 7, then run this code, you select line 7, then go to line 0, then go to line 7. This is unacceptable.
In an attempt to fix this, we tried to include the above code in the following additional lines:
chTableLayoutPanel1.SuspendLayout(); *DO CODE* chTableLayoutPanel1.ResumeLayout();
But it did not help.
So far, the most acceptable solution that we have been able to achieve is to change the color when choosing so that you cannot see it, letting it jump and then return the colors as they should be. This makes flicker more acceptable.
dgridPostings.RowsDefaultCellStyle.SelectionBackColor = SystemColors.Window; dgridPostings.RowsDefaultCellStyle.SelectionForeColor = SystemColors.ControlText; DO CODE dgridPostings.RowsDefaultCellStyle.SelectionBackColor = SystemColors.Highlight; dgridPostings.RowsDefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;
We believe that the problem is caused by the fact that the binding source is temporarily empty, because the data set is updated, then we will re-proceed to the fact that the data was received again.
Can anyone suggest any ideas on how we can prevent this unpleasant flicker?
Thank you very much
Colin