I'd like to know if there is a way to know if vertical scroll bar is displayed. I need to adjust column size based on if vertical scroll bar is shown or not. I don't want to use AutoFitStyle.ResizeAllColumns, due to some design resons. I also like to know how to get the width of vertical scroll bar. Thanks.
I'm not sure if there's a better way to do it, but one approach might be to check:
this.ultraGrid1.ActiveRowScrollRegion.VisibleRows.Count == this.ultraGrid1.Rows.Count
As for the scrollbar width, this might be determined by the system settings (though I'm not certain of this), so you could try looking at "SystemInformation.VerticalScrollBarWidth".
-Matt
Thank you for your quick response. I tried this approach, but my grid has multiple bands, this.ultraGrid1.Rows.Count only get the the rows from first band. Is there an easier way to know how much total rows a grid has instead of looping through all bands?
The downside to this approach is that you have to wait for the grid to paint before you can do anything. You might be able to force this by calling VerifyChildElements on the main grid element.
Hi Matt, thank you so much for taking your time to answer the question in great detail. This approach works!
I'd like to use this aproach after the grid data populated. I tried it in InitializeLayout event handler, but it didn't work, I guess the data wasn't pupulated at that time. Any thought on this issue?
Thanks a lot, Crystal.
Well as you know one solution is indeed to walk down each of the rows in the VisibleRows collection and check all of the child bands. The other solution would be to get this information through the various UIElements. For example, the DataAreaUIElement will include the rows/columns and the scrollbar, but its child element RowColRegionIntersectionUIElement will not include scrollbars. You might find the UIElementViewer handy if you want to take this approach.
UIElement gridElement = this.ultraGrid1.DisplayLayout.UIElement;DataAreaUIElement dataElement = gridElement.GetDescendant(typeof(DataAreaUIElement)) as DataAreaUIElement;if (dataElement != null){ RowColRegionIntersectionUIElement rcRegionElement = dataElement.GetDescendant(typeof(RowColRegionIntersectionUIElement)) as RowColRegionIntersectionUIElement; if (rcRegionElement != null) { Rectangle rectIncludingScrollbars = dataElement.Rect; Rectangle rectWithoutScrollbars = rcRegionElement.Rect; }}