Reputation: 2821
Having a tablelist I want to delete all rows containing a string in the first column.
set Joints [.dsm.nb.f11.jointData_f11 getcolumns cJoint ]
set killrow 0
foreach Joint $Joints {
if { $Joint eq "" } {
.dsm.nb.f11.jointData_f11 delete $killrow $killrow
}
incr killrow
}
The problem is that the row indexes of the table changes while rows get deleted, so that after the first delete command everything gets messd upp. What is the best way to deal with this Problem? Is there a build in feature i could use?
Upvotes: 0
Views: 530
Reputation: 137567
The simplest way of making this work is to go through the list backwards. lreverse
helps a lot.
set Joints [.dsm.nb.f11.jointData_f11 getcolumns cJoint]
set killrow 0
set rowsToKill {}
foreach Joint $Joints {
if {$Joint eq ""} {
lappend rowsToKill $killrow
}
incr killrow
}
foreach killrow [lreverse $rowsToKill] {
.dsm.nb.f11.jointData_f11 delete $killrow $killrow
}
Yes, you're iterating over the list a few times. It's still simpler to do it this way than to try to do it any other.
Upvotes: 2