Populate csv headers to ListCtrl

From:
f = open(someData, ‘rb’)
reader = csv.reader(f)
self.headers = reader.next()
print self.headers
I’d like to transfer that list set to the listmix GetColumn.
I read somewhere in this group to improvise:
item = list.GetColumn(col)
item.SetText(newtext)
list.SetColumn(col, item)
I can’t find any working examples of this.
I’ve attached a sample werner helped me on in a previous post.
Any help would be great!

csv_splitter_try.py (5.56 KB)

···

Hi George,

From:
        f = open(someData, 'rb')
        reader = csv.reader(f)
        self.headers = reader.next()
        print self.headers
I'd like to transfer that list set to the listmix GetColumn.
I read somewhere in this group to improvise:
        item = list.GetColumn(col)
        item.SetText(newtext)
        list.SetColumn(col, item)
I can't find any working examples of this.

If you use GetColumn/SetColumn you might run into problems if your current csv has more columns then the last one.

I've attached a sample werner helped me on in a previous post.
Any help would be great!

An alternative would be to take the code you currently have in createAndLayout in relation to the listctrl and split it into:

method 'createList' which receives a list of headers

if list already exists use - lc.ClearAll()
otherwise create it
create the columns using the headers passed in

method 'loadList' which loads the items to the list (see createAndLayout and reloadList)

Then call the first method in createAndLayout with a dummy header list and call both methods from your method which reads the CSV.

Werner

···

On 12/10/2013 10:59, George McCown wrote:

On the dummy function, I set up a clear headers list.

I’m using self.headers =

Then on the reloadList function I can use:

    for key, col in self.headers:  <-- too many values to unpack.
        self.InsertColumn(0, col) 

Like it’s done for the SetStringItem method.

I know I’m missing your loadlist method point.
Can you explain again?

···

On Saturday, October 12, 2013 4:32:33 AM UTC-5, werner wrote:

Hi George,

On 12/10/2013 10:59, George McCown wrote:

From:

    f = open(someData, 'rb')
    reader = csv.reader(f)
    self.headers = reader.next()
    print self.headers

I’d like to transfer that list set to the listmix GetColumn.

I read somewhere in this group to improvise:

    item = list.GetColumn(col)
    item.SetText(newtext)
    list.SetColumn(col, item)

I can’t find any working examples of this.

If you use GetColumn/SetColumn you might run into problems if your
current csv has more columns then the last one.

I’ve attached a sample werner helped me on in a previous post.

Any help would be great!

An alternative would be to take the code you currently have in
createAndLayout in relation to the listctrl and split it into:

method ‘createList’ which receives a list of headers

if list already exists use - lc.ClearAll()

otherwise create it

create the columns using the headers passed in

method ‘loadList’ which loads the items to the list (see createAndLayout
and reloadList)

Then call the first method in createAndLayout with a dummy header list
and call both methods from your method which reads the CSV.

Werner


I would have something like:
self.headers = [‘col1headertext’, ‘col2headertext’]
for this to work you woulc have to have two elements per column, not
really needed no.
colno = 0
for head in self.headers:
self.InsertColumn(colno, head)
colno += 1
Something similar as was in ‘reloadList’ without the deleting of the
items as that is already done.
Werner

···

Hi George,

  On 12/10/2013 18:29, George McCown wrote:

On the dummy function, I set up a clear headers list.

       I'm using self.headers = [] 
      Then on the reloadList function I can use:



              for key, col in self.headers:  <-- too many values

to unpack.

self.InsertColumn(0, col)

      Like it's done for the SetStringItem method.



      I know I'm missing your loadlist method point.

      Can you explain again?

Hi George,

On the dummy function, I set up a clear headers list.

       I'm using self.headers = [] 

I would have something like:

self.headers = ['col1headertext', 'col2headertext']

This method must be built-in somewhere. I assumed it needed to be set clear.

      Then on the reloadList function I can use:



              for key, col in self.headers:  <-- too many values

to unpack.

for this to work you woulc have to have two elements per column, not

really needed no.

self.InsertColumn(0, col)

colno = 0

for head in self.headers:

    self.InsertColumn(colno, head)

    colno += 1

I was on the right right track. Just needed to start reading the list at the beginning. ie, colno = 0

      Like it's done for the SetStringItem method.



      I know I'm missing your loadlist method point.

      Can you explain again?
Something similar as was in 'reloadList' without the deleting of the

items as that is already done.

Werner

Your implementation only needs just a few more lines to work. I’m adding an attachment
for anyone else to see. Back to the game. OU & Texas

csv_splitter_try.py (5.71 KB)

···

On Saturday, October 12, 2013 11:46:17 AM UTC-5, werner wrote:

  On 12/10/2013 18:29, George McCown wrote: