0

In my table i am having 5 columns in common and adding some column on the fly (Depending on the input). when the process is reloaded all the column will be deleted and the default 5 columns is created and the other columns too. The script i am using for column deletion is as :

totalColumns = self.TBL_shotDetails.columnCount()
for index in xrange(totalColumns) :
    self.TBL_shotDetails.removeColumn(index)

When running this lines of code, only the first two columns are getting deleted. And the rest are not getting deleted. Can anyone suggest me how to do this.

  • In addiction to my answer, here is a difference between range and xrange http://stackoverflow.com/questions/135041/should-you-always-favor-xrange-over-range – Qwerty Mar 13 '13 at 12:04

1 Answers1

2

Did you check the value of index? The index is still incrementing. Column which had index 3 now replaces deleted column with index 2, but you continue on deleting incrementing index.

EDIT:
You might want to delete from 7 down to 0.

Qwerty
  • 29,062
  • 22
  • 108
  • 136
  • Yes when i am adding print statement for each index its getting printed (for Eg: 0 - 7(with eight columns)) – Sudeepth Patinjarayil Mar 08 '13 at 11:59
  • Lets say you have [0,1,2,3,4,5,6,7]. You delete first column. What will happen to others? [<-,1,2,3,4,5,6,7] Will they shift or will they keep their index values? You might want to delete from 7 downto 0 OR delete 7 times index [0] – Qwerty Mar 08 '13 at 12:59
  • Thanks man i got it right. i just reversed the index and the table column is cleared. – Sudeepth Patinjarayil Mar 12 '13 at 04:52