Preventing Horizontal Scrollbars in wxGrid

Hey,

I'm working on an app where the main window contains a wxGrid tied to a
custom table with three columns and a variable number of rows. The
behavior I'm trying to get is that when the main window resizes, two
columns stay a constant width and the other fills the reamining width
allocated to the grid. The code below (adapted from the listctrl auto
resize mixin) gives almost that behavior.

    def on_gridresize(self, evt):
        wx.CallAfter(self.after_gridresize)
        evt.Skip()
        
    def after_gridresize(self):
        w, h = self.playersgrid.GetClientSizeTuple()
        totalheight = self.playersgrid.GetNumberRows()
        if totalheight:
            totalheight *= self.playersgrid.GetRowSize(0)
        if wx.Platform != '__WXMSW__':
            if totalheight > h:
                w -= wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
        self.playersgrid.SetColSize(1, w-126)
        self.playersgrid.ForceRefresh()

(on_gridresize is bound to the EVT_SIZE event of the grid, natch.)

The problem is that when the number of rows in grid is enough that the
grid needs a vertical scrollbar, I also get a horizontal scrollbar. The
columns are sized correctly - all three exactly fit on the leftmost part
of the scroll area. Scrolling right reveals a band of white space
beyond the last column which appears to be the width of the vertical
scroll bar.

Any ideas on how to get this right? The bottom line is that I never
want to see a horizontal scrollbar; the three columns should exactly
fill the width of the grid, the variable width column being shrunk as
necessary to accommodate a vertical scrollbar if needed.

Thanks in advance,
Jay

···

--
Jay Bloodworth <jbloodworth@sc.rr.com>
AOL IM: gaufqwi Yahoo! IM: augustin_damonk BSW: quarks

[snip]

Any ideas on how to get this right? The bottom line is that I never
want to see a horizontal scrollbar; the three columns should exactly
fill the width of the grid, the variable width column being shrunk as
necessary to accommodate a vertical scrollbar if needed.

You need to subtract the width of the vertical scrollbar to get what you want.
Also have a look at wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin which does
what you want for a ListCtrl.

Adi

···

Am Sat, 09 Jul 2005 17:12:53 +0200 schrieb Jay Bloodworth <jbloodworth@sc.rr.com>:

Thanks, but if you'll reexamine the code snippet I provided (which is in
fact adapted from the listctrl mixin), you'll see that I am subtracting
the scrollbar width when I set the width of the column. But perhaps
there is someplace else I should be subtracting it from. Again, the
columns are the right widths, but there is a column of empty space the
width of a vertical scrollbar to the right of the last column.

Should have said earlier: This is linux, wxGTK 2.4.2, wxpython 2.5

Thanks,
Jay

···

On Sun, 2005-07-10 at 12:39 +0200, Adi J. Sieker wrote:

You need to subtract the width of the vertical scrollbar to get what you
want.
Also have a look at wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin which
does
what you want for a ListCtrl.

--
Jay Bloodworth <jbloodworth@sc.rr.com>
AOL IM: gaufqwi Yahoo! IM: augustin_damonk BSW: quarks

Hi Jay,

You need to subtract the width of the vertical scrollbar to get what you
want.
Also have a look at wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin which
does
what you want for a ListCtrl.

Thanks, but if you'll reexamine the code snippet I provided (which is in
fact adapted from the listctrl mixin), you'll see that I am subtracting
the scrollbar width when I set the width of the column. But perhaps
there is someplace else I should be subtracting it from. Again, the
columns are the right widths, but there is a column of empty space the
width of a vertical scrollbar to the right of the last column.

I missed both of those points in your original mail. I must read mails more thoroughly...
I played around with the Grid example in the demo and it looks like the horizontal scrollbar appears when
the available space is equal or less than the width of the vertical scrollbars, no matter if the
vertical scrollbar is displayed or not. So I guess it's only possible to get rid of the horizontal
scrollbar if the total width of all columns is less than client width - vertical scrollbar width
and if the vertical scrollbars are shown then vertical scrollbar width * 2. Which also means you'll have
an empty space on the right hand side of the last column.

I would file this as a bug in the grid control.

This is on WinXP, wxPython 2.6

Adi

···

Am Sun, 10 Jul 2005 16:31:35 +0200 schrieb Jay Bloodworth <jbloodworth@sc.rr.com>:

On Sun, 2005-07-10 at 12:39 +0200, Adi J. Sieker wrote: