The attached little program creates a ListCtrl in report style. The question I am trying to answer is: What does the first argument of
InsertStringItem represent?
The wxPython documentation says it is the “index”, without explaining what that means.
The wxWidgets documentation says it is the “index of the new item, supplied by the application.” It also says that this command “inserts an item,
returning the index of the new item if successful” but, in my example, the index returned isn’t the first argument of InsertStringItem for any row.
The book wxPython in Action says on page 403: “If you are just inserting a string item into the list, use InsertStringItem(index, label), where the
index is the row in the list where the new item will be displayed.” But in my example the row number is the displayed index, which differs from the
first argument of InsertStringItem on every row. Also, the example given on page 398 of the book uses sys.maxint (i.e., the largest integer that can
be represented) for every row and it can’t be that every row has the same number.
The tutorial at http://www.zetcode.com/wxpython/advanced/ says: “The first parameter of [InsertStringItem] specifies the row number.” This is wrong
for the reasons just given.
I tried playing around with different values for the first argument and found that lots of different combinations work and produce exactly the same
table. But negative numbers give an error. Also, if the first argument of InsertStringItem equals the row number of a preceding row (e.g., give number
0 or 1 to the last row) then rows have their order changed and different rows are assigned the same index.
But I still don’t know what the first argument of InsertStringItem represents. I don’t need to know but I’m curious and so I’d be grateful if someone
could tell me.
Patrick Maher
http://patrick.maher1.net
test.py (925 Bytes)