Imam dva listBoxa
ListBox1 i ListBox2
Imam dva Buttona
Button1 i Button 2
U ListBox1 imam sledece
Item1
Item2
Item3
Item4
Item5
Item6
Item7
...
Kad kliknem na Button 1 meni se selektovani items iz listBoxa1 dodaju u ListBox2
To radi odlicno!!
Medjutim na istu foru na osnovu istog koda kako sam dodao u ListBox2 zelim sa drugim buttonom iz listBox2
da izbrisem items koje sam selektovao !!!
E TU NASTAJE PROBLEM !!
Kod:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iCtr As Integer
' List the names of the selected items ListBox1 and add to ListBox2.
For iCtr = 0 To ListBox1.SelectedItems.Count - 1
ListBox2.Items.Add(ListBox1.SelectedItems.Item(iCtr))
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim iCtr As Integer
' List the names of the selected items from ListBox2 and remove from ListBox2.
For iCtr = 0 To ListBox2.SelectedItems.Count - 1
'Ako izaberem npr da izbrisem dva selektovana itmes-a iz ListBox2
'Onda mi izbaci gresku Index was outside the bounds of the array.
'Nije mi jasno zasto izlazi ako kad testiram sa msgBox sve radi
'Samo kad ocu da uradim remove onda mi zibaci gresku
'Index was outside the bounds of the array.
ListBox2.Items.Remove(ListBox2.SelectedItems.Item(iCtr))
'Kada testiram sa MesageBoz imam sva poljsa koja treba da
'Se izbrisu
'MessageBox.Show(ListBox2.SelectedItems.Item(iCtr))
Next
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iCtr As Integer
' List the names of the selected items ListBox1 and add to ListBox2.
For iCtr = 0 To ListBox1.SelectedItems.Count - 1
ListBox2.Items.Add(ListBox1.SelectedItems.Item(iCtr))
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim iCtr As Integer
' List the names of the selected items from ListBox2 and remove from ListBox2.
For iCtr = 0 To ListBox2.SelectedItems.Count - 1
'Ako izaberem npr da izbrisem dva selektovana itmes-a iz ListBox2
'Onda mi izbaci gresku Index was outside the bounds of the array.
'Nije mi jasno zasto izlazi ako kad testiram sa msgBox sve radi
'Samo kad ocu da uradim remove onda mi zibaci gresku
'Index was outside the bounds of the array.
ListBox2.Items.Remove(ListBox2.SelectedItems.Item(iCtr))
'Kada testiram sa MesageBoz imam sva poljsa koja treba da
'Se izbrisu
'MessageBox.Show(ListBox2.SelectedItems.Item(iCtr))
Next
End Sub
End Class
Znaci na istu foru kako sto sam dodao zelim i da uradim remove!!
ListBox2.SelectedItems.Item(iCtr)
Mi daje vrednosti od Itemsa koje selektujem u ListBox2
i kad ih prikazem u MessageBox ono funkcinise !!
Ali kad uradim
ListBox2.Items.Remove(ListBox2.SelectedItems.Item(iCtr))
Dobijem gresku Index was outside the bounds of the array.
ZASTO TA GRESKA ??
Ako lepo radi sa MessageBox i nema te greske da izlazi izvan Indexa zasto lepo nece da radi
i da izbrise sve sto je selektovano??
Gde gresim ??
Pozzzzz
Sto mozes danas ne ostavljaj za sutra!