Invalid column

Could some kind guru tell me what's wrong with this bit of code please.
The first call to SetStringItem is triggering an assertion failure
"invalid column index in SetItem".

Python 2.4.1, wxPython 2.6.1. Slackware Linux 10.2

    i = 0
    self.pVAT.vRateInfo.ClearAll()
    self.pVAT.vRateInfo.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT,
      heading=u'VAT Rate Name', width=-1)
    self.pVAT.vRateInfo.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT,
          heading=u'VAT Rate value', width=-1)
    self.pVAT.vRateInfo.InsertColumn(col=2, format=wx.LIST_FORMAT_LEFT,
          heading=u'VAT Rate Date', width=-1)
    c= RunPar.dbConn.cursor()
    c.execute("SELECT b.idVAT_rates, b.IdVAT_rate_types, a.Rate_Name, b.Rate, b.Date_applicable FROM VAT_rate_values b, VAT_rate_types a WHERE a.iDVAT_rate_types = b.idVAT_rate_types")
    VAT_rates = c.fetchall()
    for rate in VAT_rates:
        self.pVAT.vRateInfo.InsertStringItem(i,rate[2])
        self.pVAT.vRateInfo.SetStringItem(i,col=1,label=str(rate[3]))
        self.pVAT.vRateInfo.SetStringItem(i,col=2,label=str(rate[4]))
        i = i + 1

douglas <douglas <at> brillhouse.co.uk> writes:

Could some kind guru tell me what's wrong with this bit of code please.
The first call to SetStringItem is triggering an assertion failure
"invalid column index in SetItem".

Sorry, but I cannot reproduce the error, neither on windows nor on linux. Can
you please post a complete example code showing the error. How did you create
your ListCtrl?

I tried the following small test app, which (i think) should simulate what you
are doing) and it works well. Does it produce an error on your system?

import wx

class MainFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title,
                          wx.DefaultPosition, wx.Size(600, 400))

        self.Panel = wx.Panel(self, -1)
        TopSizer = wx.BoxSizer(wx.VERTICAL)
        self.Panel.SetSizer(TopSizer)

        self.List = wx.ListCtrl(self.Panel, -1, style=wx.LC_REPORT)
        TopSizer.Add(self.List, 1, wx.EXPAND)

        self.List.InsertColumn(0, "Col0")
        self.List.InsertColumn(1, "Col1")
        self.List.InsertColumn(2, "Col2")
        
        for i in range(10):
            self.List.InsertStringItem(i, "Text %i.0" % i)
            self.List.SetStringItem(i, 1, label="Text %i.1" % i)
            self.List.SetStringItem(i, 2, label="Text %i.2" % i)

class MyApp(wx.App):
    def OnInit(self):
        Frame = MainFrame(None, -1, "Demo ListCtrl")
        Frame.Show(True)
        self.SetTopWindow(Frame)
        return True

if __name__ == '__main__':
    App = MyApp(0)
    App.MainLoop()

douglas <douglas <at> brillhouse.co.uk> writes:

>
> Could some kind guru tell me what's wrong with this bit of code
> please. The first call to SetStringItem is triggering an assertion
> failure"invalid column index in SetItem".
>

Sorry, but I cannot reproduce the error, neither on windows nor on
linux. Can you please post a complete example code showing the error.
How did you create your ListCtrl?

Thanks for trying Guido. I was a bit unhappy about posting all of the
app (and I don't think you would want to wade through 2000+ lines) and
there's a lot to filter out so I just did some tests. Result below.

I tried the following small test app, which (i think) should simulate
what you are doing) and it works well. Does it produce an error on
your system?

That worked fine, which proved to me that the calls were not the problem
and caused me to look elsewhere. A bit of semi-random hacking at the
code revealed that the problem was I had LC_LIST specified as part of
the style for the ListCtrl.

Reading the documentation again still does not scream to me that LC_LIST
and the sort of control I was trying to achieve do not fit together.

Note to whoever is responsible for the documentation - Perhaps a little
more in the way of explanation would help (probably on the SetStringItem
method).

···

On Tue, 27 Dec 2005 12:37:22 +0000 (UTC) Guido Roth <RothGuido@gmx.de> wrote:

Note to whoever is responsible for the documentation - Perhaps a little
more in the way of explanation would help (probably on the SetStringItem
method).

From the wxWidgets Reference:

wxListCtrl::InsertColumn
long InsertColumn(long col, wxListItem& info)

long InsertColumn(long col, const wxString& heading, int format =
wxLIST_FORMAT_LEFT, int width = -1)

For report view mode (only), inserts a column. For more details, see
wxListCtrl::SetItem.