Listbox Index Error

1

My application has the following start code:

BuscaDiretorioPastaOriginal("Diretorio") // isso seria uma função **recursiva** de diretorios
BuscaDiretorioPastaPath("Diretorio") // isso seria uma função **recursiva** de diretorios

This function lists two listBox , so add everything, but delete the error in this function

Private Sub AnalisarNovoArquivo()

 CTN.LSTNewAqui.Items.Add(CTN.LSTOG.SelectedItem.ToString)  
 CTN.LSTOG.Items.Remove(CTN.LSTOG.SelectedItem.ToString)

 CTN.LSTNewAqui.SelectedIndex = 0 
 ListaArray(0) = CTN.LSTNewAqui.SelectedItem.ToString  'Adiciona ao Index 0 na lista de array

end sub 

This part of the function asserts that the value is not valid for selectedIndex , the reason would be for the upper part where it has CTN.Items.Remove(CTN.LSTOG.SelectedItem.ToString) .

OBS: The function works correctly if you use a Try , but how do you return this error?

Function reporting the error:

    Try
        For ItemsI = 0 To CTN.LSTOG.Items.Count - 1
            CTN.LSTOG.SelectedIndex = ItemsI
            CTN.LSTPath.SelectedIndex = ItemsI

            If CTN.LSTOG.SelectedItem.ToString <> CTN.LSTPath.SelectedItem.ToString Then
                Notificar("Existem novos arquivos a serem adicionados ao projeto.")
                AnalisarNovoArquivo()
                IniciarBuscaDeNovoArquivo()
                SplitCaminho()
                rem  VerificarDiretorios()
                CopiarNovoArquivo()
            End If
        Next
    Catch ex As Exception


    End Try
    
asked by anonymous 13.11.2014 / 21:23

1 answer

2
Private Sub AnalisarNovoArquivo()

  CTN.LSTNewAqui.Items.Add(CTN.LSTOG.SelectedItem.ToString)  
  CTN.LSTOG.Items.RemoveAt(CInt(CTN.LSTOG.SelectedIndex))

  CTN.LSTNewAqui.SelectedIndex = 0 
  ListaArray.Items.Insert(0, CTN.LSTOG.SelectedItem.ToString)

end sub 
    
07.05.2015 / 20:59