Jump to content

Eliminar elemento da listbox com duplo clique


maluco2able
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.