Hi,
I have a grid setup without a scrollbar (I've used the this.DisplayLayout.MaxRowScrollRegions = 1; property, which I believe forces the entire grid to display without the need for scrolling). The reason that I'm doing this is that I'm embedding the grid as a whole into another control for viewing all in one big snapshot. In order to do this, I'm adding the grid to a container. The container sometimes needs to know the final size of that grid in order to know how to big to make itself. I've taken a look at the Height property on the UltraGrid, but that doesn't seem to give the right height of the final grid with data (the resulting grid in my case ends up being quite large...anywhere from 100 to 1000 rows tall). Is there some property that I'm missing which would give me a good indicator of how long vertically the grid is (including headers)? I've tried doing back of the hand calculation that looks something like this: <Height of header> + <Number of rows> * <DefaultRowHeight property>, but that doesn't give me a correct height either.
Thanks,
Charley
Hi Charley,
tamalecharley said:I have a grid setup without a scrollbar (I've used the this.DisplayLayout.MaxRowScrollRegions = 1; property, which I believe forces the entire grid to display without the need for scrolling).
No, that's not what this property does. All it does is remove the user's ability to create multiple scroll regions by dragging the little button on top of the vertical scroll bar.
The grid has no mode where it will automatically adjust it's height to the contents. This is, in fact, very complex and difficult for the grid to do internally, because there are so many possible options. It's a little easier for you to do it yourself, since you can make assumptions about which features you are using.
You would have to account for the headers (column and band), the height of every row, and the horizontal scrollbar (if there is one). If the rows are all the same height, then you could just multiply the row height times the number of rows, but even this can be tricky, because sometimes the rows overlap by a pixel, depending on the RowLayoutStyle and the border styles of the cells and the rows.
Interesting. What I've been attempting for the self-calculation of the grid height is something like this:
ultraGrid1.Rows.Count * ultraGrid1.DisplayLayout.Override.DefaultRowHeight + ultraGrid1.DisplayLayout.Bands[0].Columns[0].Header.Height. What is the Band header you mentioned? I think another tricky bit to the calculation (which maybe you are already mentioning and I'm not realizing it), is the existence of grid lines. Perhaps the fact that I have grid lines to deal with is throwing off the height calculation? If that's the case, perhaps I can scale the DefaultRowHeight by a pixel or two
DefaultRowHeight is probably not right. That's just the default height of the row, not the actual height. If all of your rows are the same height, then I would use the height of the first row.
ultraGrid1.Rows[0].Height
This, of course, assumes that there is at least one row and that all of the rows are the same height (RowSizing = Synchronized). If the rows are not all the same size, then you would, of course, have to loop through every row and sum up the heights.
The band header can be shown by setting band.HeaderVisible to true. It's hidden by default.
I'm not sure what you mean by "grid lines".
To clarify by what I meant by gridlines: we put a border on each side of our cells to create the appearance of grid lines. I think it adds a pixel or two so hopefully if I scale the row height accordingly it will work.