ListCtrl column resizing

Hello,

You use GetClientSize() when calling ResizeColumns() which already gives
you the size of the ListCtrl *without* scrollbars.

From the documentation:

virtual wxSize GetClientSize() const

This gets the size of the window 'client area' in pixels. The client
area is the area which may be drawn on by the programmer, excluding
title bar, border, scrollbars, etc.

Here is the code I use to solve the same problem:

        wx.EVT_SIZE(self, self.OnSize)

    def OnSize(self, event):
        size = self.GetClientSize()
        width = size.width
        i = 1
        count = self.GetColumnCount()
        while i < count:
            width -= self.GetColumnWidth(i)
            i += 1
        self.SetColumnWidth(0, width)
        event.Skip()
        
I still get this annoying horizontal scrollbar after I maximize then
minimize my frame. I tried to decrement the width of the first column
but the horizontal scrollbar still appears. Does anyone know how to hide
it?

···

-----Original Message-----
From: Adi Sieker [mailto:ml@sieker.info]
Sent: Friday, March 19, 2004 11:59 AM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] ListCtrl column resizing

Hi,

I have a ListCtrl with 3 columns.
the last 2 columns are going tobe fixed width and
the first one should fill up the rest of the space without causing
horizontal scroll bars.
I have this working, like this:

def ResizeColumns(self, size):
     sb = wx.ScrollBar(self, style=wx.SB_VERTICAL)
     sbSize = sb.GetSize()
     sb.Destroy()
     self.SetColumnWidth(0, size.width - 40 - sbSize.width -7)
     self.SetColumnWidth(1, 20)
     self.SetColumnWidth(2, 20)

and ResizeColumns get called like this:
     def OnSize(self, event):
         self.todoList.ResizeColumns(self.GetClientSize())

What annoys me is that I have to add an extra - 7 pixels
for this to work and I'm not sure that this will work on all Plattforms.
I would have thought that client size - scrollbar width would do the
trick.

Anyone have an idea

Regards
     Adi

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hi,

I made a little example script which shows this behaviour.
To me it looks like a bug of wxWidgets.

Oh, nearly forget wxP 2.5.1.1, with Python 2.3.2 under WindowsXP

Regards
     Adi

import wx

class MyLisTctrl(wx.ListCtrl):
     def __init__(self,parent ):
         wx.ListCtrl.__init__(
             self, parent, -1,
             style=wx.LC_REPORT|wx.LC_HRULES|wx.LC_VRULES
             )

         self.InsertColumn(0, "Client Width")
         self.InsertColumn(1, "dummy")
         self.ResizeColumns()

     def ResizeColumns(self):
         size = self.GetClientSize()
         self.InsertStringItem(0, "ClientSize width: %s" %(size.width))
         self.SetColumnWidth(0, size.width - 40)
         self.SetColumnWidth(1, 40)

class MyFrame(wx.Frame):
     def __init__(self, parent, id, title,pos=wx.Point(50,50), size=wx.Size(400, 400)):
         wx.Frame.__init__(self, parent, id, title, pos=pos, size=size,
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)

         wx.EVT_CLOSE(self, self.OnCloseWindow)
         wx.EVT_SIZE(self, self.OnSize)

         theSizer = wx.BoxSizer(wx.VERTICAL)
         self.lc = MyLisTctrl(self)

         theSizer.Add(self.lc, 1, wx.EXPAND, 0)

         self.SetAutoLayout(1)
         self.SetSizer(theSizer)
         self.Layout()

     def OnCloseWindow(self, event):
         return self.Destroy()

     def OnSize(self, event):
         self.lc.ResizeColumns()
         event.Skip()

class MyApp(wx.App):
     def OnInit(self):
         self.frame = MyFrame(None, -1, "MyTestApp")
         self.frame.Show(True)

         return True

if __name__ == '__main__':
     app = MyApp()
     app.MainLoop()

M. Vernier wrote:

···

Hello,

You use GetClientSize() when calling ResizeColumns() which already gives
you the size of the ListCtrl *without* scrollbars.

From the documentation:

virtual wxSize GetClientSize() const

This gets the size of the window 'client area' in pixels. The client
area is the area which may be drawn on by the programmer, excluding
title bar, border, scrollbars, etc.

Here is the code I use to solve the same problem:

        wx.EVT_SIZE(self, self.OnSize)

    def OnSize(self, event):
        size = self.GetClientSize()
        width = size.width
        i = 1
        count = self.GetColumnCount()
        while i < count:
            width -= self.GetColumnWidth(i)
            i += 1
        self.SetColumnWidth(0, width)
        event.Skip()
        I still get this annoying horizontal scrollbar after I maximize then
minimize my frame. I tried to decrement the width of the first column
but the horizontal scrollbar still appears. Does anyone know how to hide
it?

-----Original Message-----
From: Adi Sieker [mailto:ml@sieker.info] Sent: Friday, March 19, 2004 11:59 AM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxPython-users] ListCtrl column resizing

Hi,

I have a ListCtrl with 3 columns.
the last 2 columns are going tobe fixed width and
the first one should fill up the rest of the space without causing horizontal scroll bars.
I have this working, like this:

def ResizeColumns(self, size):
     sb = wx.ScrollBar(self, style=wx.SB_VERTICAL)
     sbSize = sb.GetSize()
     sb.Destroy()
     self.SetColumnWidth(0, size.width - 40 - sbSize.width -7)
     self.SetColumnWidth(1, 20)
     self.SetColumnWidth(2, 20)

and ResizeColumns get called like this:
     def OnSize(self, event):
         self.todoList.ResizeColumns(self.GetClientSize())

What annoys me is that I have to add an extra - 7 pixels
for this to work and I'm not sure that this will work on all Plattforms.
I would have thought that client size - scrollbar width would do the
trick.

Anyone have an idea

Regards
     Adi

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org