Hello,I want to implement functionality to refresh ultragrid without refreshing the row which the user is editing that is the row in which user is entering the value.I am displaying ultragrid by binding the datatable to it.Means no columns added design time but will be displayed as per data in datatable.To refresh the grid I am not using inbuilt refresh method provided by ultragrid but I simply bind the data source again.So when grid is refreshed all rows should be same as when it was first displayed but the row which I was editing should be as it was left.Is there any inbuilt property or method available for that?Or any other way to implement this?
Thank you.
Setting the DataSource of the grid will blow away all of the rows and columns and create new ones based on the data source, so you should avoid that if possible.
If your data source implements IBindingList, then it will automatically notify the grid of any changes. If it does not and you want the grid to pick up changes, then you can try calling grid.Rows.Refresh(ReloadData).
Hi,
I am not sure, but I have the following:
ultragrid.Datasource = datasource;
As you mentioned before this will re create all rows, I dont want that because I am scrolling down to find something and my application is set to refresh the data periodically so it gets me to the top of the grid again.
I want to keep refreshing the data but dont want to be sent back to the top every time I refresh it.
So setting the Datasource every time I want to refresh my data gives me problems, I tried this: grid.Rows.Refresh(ReloadData), but I am not sure if I am using it correctly but my grid is never being updated.
What do you suggest me to do?
acgc said: I am not sure, but I have the following: ultragrid.Datasource = datasource;
What do you mean you are not sure? You don't know what your datasource object is? You should be able to tell this by simply looking at this variable and finding it's declaration so you can see what type it is.
acgc said: As you mentioned before this will re create all rows, I dont want that because I am scrolling down to find something and my application is set to refresh the data periodically so it gets me to the top of the grid again. I want to keep refreshing the data but dont want to be sent back to the top every time I refresh it.
If you a periodically refreshing the data and setting the grid's DataSource, then I don't see any way to avoid this. You should avoid re-setting the DataSource on the grid whenever possible.
acgc said: So setting the Datasource every time I want to refresh my data gives me problems, I tried this: grid.Rows.Refresh(ReloadData), but I am not sure if I am using it correctly but my grid is never being updated. What do you suggest me to do?
Again, it depends what kind of DataSource you are using and what you are trying to do. Re-setting the DataSource property on the grid is a very destructive action. When you do this, the BindingManager in DotNet throws away all of the rows it was using an creates a set of new ones, so the grid has to do the same. If you set the DataSource on the grid, any row or cell level properties will always be lost including the ActiveRow, the SelectedRows, the Expanded state of the rows, and the scroll position of the grid. There is no way the grid can avoid this because the grid has no way to associate the old rows with the new ones.
You could try to maintain all of the state information by storing some sort of key information for each row and restoring it afterward, but you would have to store everything I mentioned above and maybe some other stuff, too.
I don't know what advice to give you about using grid.Rows.Refresh(ReloadData) because I don't know how you are using it, so I can't tell you if you are using it incorrectly. This method tells the grid to refresh the display based on the current data in the datasource.
If you make changes to your data source, you typically don't have to do anything to get the grid to update it's display - it does this automatically as long as your data source tells the grid that something changed.
You only need to use the Refresh method if you are using a DataSource that does not implement IBindingList - which is to say you are using a DataSource that is not really robust and not intended to be used for DataBinding.
In such a case, you call grid.Rows.Refresh(ReloadData) to tell the grid that something has changed, since your DataSource is not doing so.
Hi Mike,
Thanks for the reply. I am using a DataTable. It is always being updated, lets say for example every 5 seconds(it is configurable). When I scroll down in the grid looking for some particular information, I don't want to be sent to the top every time it refreshes.
I've read that some guys are taking a snapshot of the grid before updating(I dont know how to do so), others are using this approach:
private UltraGridRow GetRowForObject(UltraGrid grid,object savedObject)
{
foreach (UltraGridRow row in grid.Rows)
if (row.ListObject == savedObject)
return row;
return null;
}
I think it is not working.
Maybe you need more information.