Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add rows to an existing Data Grid 1

Status
Not open for further replies.

cruise95

Programmer
Oct 7, 2003
56
US
I am unsure how to add rows to an existing datagrid.

IE.
When the application starts a dataTable is created from a resultset and a data grid is bound to this datatable.

The application updates every 15 seconds via another query to an MS SQL database. All new records in the database are added to the dataGrid so the datagrid holds all previous data and the new rows that have been added to the database in the past 15 seconds.

The real hard part is that I would like to do this without re-creating or re-freshing the datagrid every time. For example, if the user scrolls down to the 50th record, then after 15 seconds I would like the datagrid to have all of the previous data, the new data. I do not want the datagrid to refresh so that the 50th row that the user scrolled down to is lost. This way if the user scrolls to a certain row, then that row remains in the same place on the screen until the user scrolls up or down.

Question:
How do I go about adding new rows to a datagrid without having it loose the user's place?

I appreciate any help
 
I just did some testing, and using the DataSet's .Merge method added rows to a grid without the need for a refresh. This means that whatever row I had scrolled to at that point remained visible after the .Merge. However, if I had a row selected, the .Merge unselected that row, so you may need to determine if a row is selected, and re-select it after the merge. Also, I did not test this with the grid resorted, the records filtered, or anything else like that. There may be issues with rows being added that will come before a row the user is currently viewing, which would move the location of that row.

This brings up another issue. I am not sure what effect this will have if someone is in the middle of editing a record in the datagrid when the .Merge occurs.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Great...thanx jebenson!

I was looking for a way to add to a datagrid...I've never used the Merge function of a dataset and never even thought to pursue that route. Since the dataGrid is bound to my dataset, then it makes sense that any changes in the dataset would be reflected in the datagrid

Thank you again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top