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
Get visible columns from previously saved DisplayLayout / keep applying layout while changing data source

I'm trying to optimize code that displays a grid from a database query. Right now (vastly simplified), we:

  1. do a SELECT TOP 0 * from the database view and set that as the data source for the grid. That way, we know what columns potentially exist.
  2. if any, apply a user's previously saved display layout. Now, only their selected columns are visible (and groupby, filter, sort, etc. are applied).
  3. take the visible columns, and pass them on to do the actual query.
  4. "fill" the invisible remainder of the grid with NULL values

This works, vastly reduces the data transmitted, and helps the grid understand that these are "compatible" layouts. But it is in practice quite inefficient (for example, filtering can noticeably lag). What I'd prefer is for the grid to internally work with columns that actually exist; i.e. to skip step 4.

What I'd like to move towards is something like:

  1. figure out which columns potentially exist
  2. if any, fetch the user's previously saved display layout. We can't apply this yet because the grid doesn't have a data source (unless there's a way to get the grid to accept a display layout while not really having any data source?). But we can inspect which columns are visible. It seems I could simply do new UltraGridDisplayLayout(), then LoadFromXml(), and finally look at its properties.
  3. take those visible columns from the layout, and pass them on to do the actual query.
  4. set the grid data source, based on the actual query.
  5. actually apply the layout. However, this seems to require loading it twice. There is no setter for DisplayLayout.

I don't really mind step 5, but it seems a little inefficient. I could also simplify step 2, perhaps by specifying PropertyCategories.Bands.

But the bigger issue I run into right now is that the grid "forgets" some of the display layout along the way (such as sorted columns and groupby columns). Is there a way to "merge" the current grid's state to a new data source?

Is there something much easier that I'm missing to accomplish this? :)