Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2325
Correct way to refresh grid data source?
posted

I have a grid with a lot of things happening(formulas etc...)... unfortunately there are times when the grid can only do so much and I need to dump the data source, massage it, then put it back into the grid.  I do this in the following way:

var productLines = (List<CostModel>)grdMain.DataSource;
 // ... do some data massaging...
grdMain.ResetLayouts();
grdMain.DisplayLayout.Bands[0].Reset();
grdMain.DataSource = null;
grdMain.DataSource = productLines;

This seems to work, but I am wondering if this is the correct way of dealing with my data needs?  My concern is making sure all the formulas and stuff are reset.  Plus I dont want to cause any potential problems using the grid as this grid is heavily used and other grids are dependent upon the data contained therein.

So I guess I just need to know the preferred method of refreshing a grids data source.

thanks

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    This seems like overkill to me. But it really depends on exactly what you are doing to the data source.

    In a typical case, the grid will automatically respond to changes in the data source, so you shouldn't need to do this. In your case, however, I noticed that your DataSource is a List<T>, which is not an ideal data source to use and doesn't provide all of the proper notifications for data binding. If you can, I recommend using BindingList<T>, instead. It derives from List<T>, so you shouldn't have to change any of our code, and it will provide a better experience when binding to the grid.

    Of course, there are still some things you could do to your data source that the grid might not be able to detect (like sorting, for example). So in that case, a less destructive way of refreshing the grid is to call:

    grid.Rows.Refresh(ReloadData)

    This will tell the grid to reload all of the data (but will not affect the data structure, bands, or columns). It's a lot more performant than what you are currently doing.

Reply Children
No Data