Make wxListCtrl fit around contents and parent frame fit around listctrl

Piet pit.grinja at gmx.de
Sun Jul 18 04:27:23 EDT 2004


Hello,
I am working on a graphical MySQL Frontend written in python/wxPython.
The results from a table query are displayed either in a wxGrid or in
a wxListCtrl. I would prefer the latter because it underlines the
read-only character of the data, but I am not happy with the way the
results are displayed.
The wxGrid with the results is laid out by the following code:
resultsFrame = wxFrame(parent,-1,title)
resultsTable = wxGrid(resultsFrame,-1)
#populate grid with results...
resultsTable.Fit()
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(resultsTable,1,wxEXPAND)
resultsFrame.SetSizer(sizer)
resultsFrame.SetAutoLayout(True)
sizer.Fit(resultsFrame)
resultsFrame.Show(True)
This ensures that each column of the grid is adjusted to fit the
longest cell and that the wxFrame fits around the grid. However, I
have not found a way to achieve the same results for a wxListCtrl
despite trying several combinations of  .Fit()-functions. For example,
the following code
resultsFrame = wxFrame(parent,-1,title)
resultsList = wxListCtrl(resultsFrame,-1,style =
wxLC_REPORT|wxLC_VRULES|wxLC_HRULES)
#populate wxListCtrl
resultsList.Fit()
resultsList.EnsureVisible(True)
resultsList.SetColumnWidth(-1,-1)
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(resultsList,1,wxEXPAND)
resultsFrame.SetSizer(sizer)
resultsFrame.SetAutoLayout(True)
sizer.Fit(resultsFrame)
resultsFrame.Fit()
resultsFrame.Show(True)
always generates a Frame of the same size, regardless of the length
and width of the listctrl. I have checked the wxListCtrl
documentation, but I couldn't find the information I was looking for.
Does anyboy know how to format a wxListCtrl that displays all of its
information without scrolling and/or resizing columns?
THanks in advance
Piet



More information about the Python-list mailing list