Multiple deletions in listbox

From: Alexander (alexander_at_edem.g12.br)
Date: 04/13/04


Date: 12 Apr 2004 17:25:09 -0700

Hi all!

I try delete multiple selections in one listbox but something in my
code is very wrong.

The error is obvious for me, but I can't write someting right. :(

I run one loop in list of "curselection". In each of itens I do one
"delete". But the index change when I delete one item. Because this
"delete" my loop delete wrong item.

So... can you help me?

PS: forget stupid lines "insert". Is just for show something.

Very thanks and sorry again and again for my horrible english!
Alexander
Brazil-Rio de Janeiro

#!/usr/bin/wish

listbox .lista1 -selectmode multiple -yscrollcommand { .rolagem set }
scrollbar .rolagem -command {.lista1 yview}
button .botao_ver -text "apenas ver item selecionado" -command {
excluir_item }

proc excluir_item {} {

  foreach indice_item [.lista1 curselection] {
        .lista1 delete $indice_item
  }

}

.lista1 insert end "item1"
.lista1 insert end "item2"
.lista1 insert end "item3"
.lista1 insert end "item4"
.lista1 insert end "item5"

pack .lista1 -side left
pack .rolagem -expand 1 -fill y
pack .botao_ver