Sizing SGrid so ScrollBars do now appear

Summary

Id: 11.13
Type: Issue Issue
Current Status: Open

Detail

15 Mar 2003 Open Jeff Hedlund

Is there a way to resize the sgrid depending on the presence of a scrollbar? I did some testing and did not see a way. What I'm trying to do is display a single row. This works great without scrollbars. But if the user resizes a column the scroll bars appear and then the row is hidden.

The alternative is to make room for the scroll bar, but then there is a blank white spot when there is no scroll bar.

I've also noticed this (which appears to be a bug): getting rid of the bottom scroll bar *with a right scrollbar* requires me to pad extra width on the control, so you can see a little past the last [visible] column.

These things are both always something of a problem in controls which may or may not have a scroll bar.

9 Nov 2003 Open Steve McMahon

There isn't currently a method which you can use to ensure that the grid is autosized to display a certain row (or number of rows) regardless of whether the bottom scroll bar is displayed or not. Possible options (other than leaving room for the scroll bar) are:

1) Prevent the user from resizing columns

2) Respond to column sizing changes and check if the grid is displaying a scroll bar. If it is, add the height of the scroll bar to the control, otherwise remove it.

The way to do the second is as follows.

Firstly, you can detect if there is a scroll bar using code like this (really there should be properties which do this automatically):

  lStyle = GetWindowLong(grd.hWnd, GWL_STYLE)
  If (lStyle And WS_HSCROLL) = WS_HSCROLL Then
     ' grid has horizontal scroll
  End If
  If (lStyle And WS_VSCROLL) = WS_VSCROLL Then
     ' grid has vertical scroll
End If
 

With that info, you can now determine the extra room in the control required for the scroll bar using the GetSystemMetrics call using SM_CYHSCROLL (vertical size of horizontal scroll bar) and SM_CXVSCROLL (horizontal size of vertical scroll bar).

As for the second bug, I will look into it.