maluco2able Posted March 28, 2012 Report Share Posted March 28, 2012 Private Sub lstNomes_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstNomes.DoubleClick If lstNomes.SelectedIndex <> -1 Then lstNomes.Items.RemoveAt(lstNomes.SelectedIndex) Try Dim Ficheiro As New FileStream("Nomes.txt", FileMode.Create, FileAccess.Write) Dim StreamEscrita As New StreamWriter(Ficheiro, System.Text.Encoding.Default) StreamEscrita.BaseStream.Seek(0, SeekOrigin.Begin) StreamEscrita.Close() Ficheiro.Close() Catch ex As Exception MsgBox("Erro: " & ex.Message) End Try End If End Sub Tenho uma duvida em relaçao ao ciclo para eliminar o elemento da listbox utilizando o doubleclick Obrigado Link to comment Share on other sites More sharing options...
ribeiro55 Posted March 28, 2012 Report Share Posted March 28, 2012 Qual ciclo? Qual é o erro? Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
maluco2able Posted March 28, 2012 Author Report Share Posted March 28, 2012 pelo que o meu professor disse tenho que fazer um ciclo for para escrever todos os elementos do ficheiro txt para a listbox, para depois utilizando o duplo clique para eleminar o elemento selecionado da listbox. Link to comment Share on other sites More sharing options...
ribeiro55 Posted March 28, 2012 Report Share Posted March 28, 2012 E é essa a tua dúvida? Precisas de saber fazer o ciclo? Depois de remover o item, podes iterar a listbox e fazer a escrita, ou seja, no espaço que deixaste antes do .Close, podes fazer algo como: For Each It As String In lstNomes.Items 'presumindo que são strings na lista 'escreve linha para o ficheiro Next Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
maluco2able Posted March 28, 2012 Author Report Share Posted March 28, 2012 obrigado pela ajuda. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now