LISTBOX TIMER
preciso listar os arquivos de uma pasta só que preciso checar em tempo real, estou usando um timer, só que ja tentei de varias formas e nao consegui fazer com que exiba só 1 vez os itens da pasta... sempre ele vai adicionando e nao para mais! alguem tem ideia de como posso fazer isso?
Limpe a lista antes de carregar os dados.
List.Clear()
[ô] Carregar dados
entao eu ponho pra limpar, e nao limpa ele vai adicionando igual louco
Poste a função que está dentro do timer... Onde você está limpando e carregando a Lista.
em .net a sintaxe correta seria = List.Items.Clear() , no começo da rotina do seu timer
Imports System.Web
Public Class URLForm
Private Sub URLForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
If My.Settings.showtip = True Then NotifyIcon1.ShowBalloonTip(1)
e.Cancel = True
End Sub
Private Sub URLForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SITE As String = Nothing
Dim browser As SHDocVw.InternetExplorer
Dim myDoc As mshtml.IHTMLDocument2
Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows()
Dim filename As String
For Each ie As SHDocVw.InternetExplorer In shellWindows
filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower()
If filename = [Ô]iexplore[Ô] Then
browser = ie
myDoc = browser.Document
Dim url As Uri = New Uri(myDoc.url)
Dim VideoId As String = HttpUtility.ParseQueryString(url.Query).Get([Ô]url[Ô])
Try
For f = Len(VideoId) To 1 Step -1
SITE += Mid(VideoId, f, 1)
Next f
lstbox_sitelist.Items.Add(SITE)
SITE = Nothing
Catch ex As Exception
End Try
End If
Next
If lstbox_sitelist.Items.Count > 0 Then lstbox_sitelist.SelectedIndex = 0
tslb_urlfound.Text = lstbox_sitelist.Items.Count & [Ô] Site(s) Invertido(s).[Ô]
End Sub
Private Sub lstbox_sitelist_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstbox_sitelist.DoubleClick
Try
Process.Start(lstbox_sitelist.SelectedItem)
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
Private Sub AtualizarListaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AtualizarListaToolStripMenuItem.Click
lstbox_sitelist.Items.Clear()
Call URLForm_Load(sender, e)
End Sub
Private Sub SairToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem.Click
Me.Dispose()
End Sub
Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click
Call lstbox_sitelist_DoubleClick(sender, e)
End Sub
Private Sub CopiarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopiarToolStripMenuItem.Click
My.Computer.Clipboard.SetText(lstbox_sitelist.SelectedItem)
End Sub
Private Sub SalvarListaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalvarListaToolStripMenuItem.Click
[ô]Verifica se há dados
If lstbox_sitelist.Items.Count <= 0 Then
MsgBox([Ô]Não há dados a serem salvos.[Ô], MsgBoxStyle.Critical, [Ô]Erro!![Ô])
Exit Sub
End If
[ô]variavel que irá gravar o caminho do novo arquivo .txt
Dim Caminho As String
SaveFileDialog1.FileName = [Ô][Ô]
SaveFileDialog1.ShowDialog()
Caminho = SaveFileDialog1.FileName
[ô]Se o usuário cancelar e não escolher o caminho, para o fluxo de execucao da sub
If Caminho = [Ô][Ô] Then Exit Sub
[ô]Verifica se o arquivo existe
If IO.File.Exists(Caminho) = False Then
[ô]O Arquivo não existe cria um novo arquivo
IO.File.Create(Caminho).Close()
End If
[ô]Cria o StreamWriter para escrver em arquvios
Dim ESCREVER As New IO.StreamWriter(Caminho)
[ô]variavel para percorrer o ListBox e salvar linha por linha
Dim i As Integer
[ô]Cria um cabeçalho no arquivo de texto
If My.Settings.showdate = True Then
ESCREVER.WriteLine([Ô]Lista criada em [Ô] & DateAndTime.Now.Date)
ESCREVER.WriteLine([Ô]----------------------------------------------------------[Ô])
[ô]ESCREVER.WriteLine()
End If
For i = 0 To lstbox_sitelist.Items.Count - 1
ESCREVER.WriteLine(lstbox_sitelist.Items(i))
Next
[ô]Cria um rodapé no arquivo
[ô]ESCREVER.WriteLine()
ESCREVER.WriteLine([Ô]----------------------------------------------------------[Ô])
[ô]ESCREVER.WriteLine([Ô]Salvo[Ô])
[ô]ESCREVER.WriteLine()
[ô]Fecha o stream do arquivoe finaliza
ESCREVER.Close()
MsgBox([Ô]Arquivo salvo com sucesso!![Ô], MsgBoxStyle.Information, [Ô]Salvo!![Ô])
End Sub
Private Sub ConfiguraçõesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfiguraçõesToolStripMenuItem1.Click
ConfigForm.ShowDialog()
End Sub
Private Sub NotifyIcon1_BalloonTipClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.BalloonTipClicked
My.Settings.showtip = False
My.Settings.Save()
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Show()
End Sub
Private Sub ExcluirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcluirToolStripMenuItem.Click
lstbox_sitelist.Items.RemoveAt(lstbox_sitelist.SelectedIndex)
End Sub
Private Sub AbrirTodosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirTodosToolStripMenuItem.Click
For i = 0 To lstbox_sitelist.Items.Count
Try
Process.Start(lstbox_sitelist.Items(i))
Catch ex As Exception
MsgBox(ex)
End Try
Next
End Sub
Private Sub SairToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem1.Click
Me.Dispose()
End Sub
Public Class URLForm
Private Sub URLForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
If My.Settings.showtip = True Then NotifyIcon1.ShowBalloonTip(1)
e.Cancel = True
End Sub
Private Sub URLForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SITE As String = Nothing
Dim browser As SHDocVw.InternetExplorer
Dim myDoc As mshtml.IHTMLDocument2
Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindows()
Dim filename As String
For Each ie As SHDocVw.InternetExplorer In shellWindows
filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower()
If filename = [Ô]iexplore[Ô] Then
browser = ie
myDoc = browser.Document
Dim url As Uri = New Uri(myDoc.url)
Dim VideoId As String = HttpUtility.ParseQueryString(url.Query).Get([Ô]url[Ô])
Try
For f = Len(VideoId) To 1 Step -1
SITE += Mid(VideoId, f, 1)
Next f
lstbox_sitelist.Items.Add(SITE)
SITE = Nothing
Catch ex As Exception
End Try
End If
Next
If lstbox_sitelist.Items.Count > 0 Then lstbox_sitelist.SelectedIndex = 0
tslb_urlfound.Text = lstbox_sitelist.Items.Count & [Ô] Site(s) Invertido(s).[Ô]
End Sub
Private Sub lstbox_sitelist_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstbox_sitelist.DoubleClick
Try
Process.Start(lstbox_sitelist.SelectedItem)
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
Private Sub AtualizarListaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AtualizarListaToolStripMenuItem.Click
lstbox_sitelist.Items.Clear()
Call URLForm_Load(sender, e)
End Sub
Private Sub SairToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem.Click
Me.Dispose()
End Sub
Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click
Call lstbox_sitelist_DoubleClick(sender, e)
End Sub
Private Sub CopiarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopiarToolStripMenuItem.Click
My.Computer.Clipboard.SetText(lstbox_sitelist.SelectedItem)
End Sub
Private Sub SalvarListaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalvarListaToolStripMenuItem.Click
[ô]Verifica se há dados
If lstbox_sitelist.Items.Count <= 0 Then
MsgBox([Ô]Não há dados a serem salvos.[Ô], MsgBoxStyle.Critical, [Ô]Erro!![Ô])
Exit Sub
End If
[ô]variavel que irá gravar o caminho do novo arquivo .txt
Dim Caminho As String
SaveFileDialog1.FileName = [Ô][Ô]
SaveFileDialog1.ShowDialog()
Caminho = SaveFileDialog1.FileName
[ô]Se o usuário cancelar e não escolher o caminho, para o fluxo de execucao da sub
If Caminho = [Ô][Ô] Then Exit Sub
[ô]Verifica se o arquivo existe
If IO.File.Exists(Caminho) = False Then
[ô]O Arquivo não existe cria um novo arquivo
IO.File.Create(Caminho).Close()
End If
[ô]Cria o StreamWriter para escrver em arquvios
Dim ESCREVER As New IO.StreamWriter(Caminho)
[ô]variavel para percorrer o ListBox e salvar linha por linha
Dim i As Integer
[ô]Cria um cabeçalho no arquivo de texto
If My.Settings.showdate = True Then
ESCREVER.WriteLine([Ô]Lista criada em [Ô] & DateAndTime.Now.Date)
ESCREVER.WriteLine([Ô]----------------------------------------------------------[Ô])
[ô]ESCREVER.WriteLine()
End If
For i = 0 To lstbox_sitelist.Items.Count - 1
ESCREVER.WriteLine(lstbox_sitelist.Items(i))
Next
[ô]Cria um rodapé no arquivo
[ô]ESCREVER.WriteLine()
ESCREVER.WriteLine([Ô]----------------------------------------------------------[Ô])
[ô]ESCREVER.WriteLine([Ô]Salvo[Ô])
[ô]ESCREVER.WriteLine()
[ô]Fecha o stream do arquivoe finaliza
ESCREVER.Close()
MsgBox([Ô]Arquivo salvo com sucesso!![Ô], MsgBoxStyle.Information, [Ô]Salvo!![Ô])
End Sub
Private Sub ConfiguraçõesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfiguraçõesToolStripMenuItem1.Click
ConfigForm.ShowDialog()
End Sub
Private Sub NotifyIcon1_BalloonTipClicked(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.BalloonTipClicked
My.Settings.showtip = False
My.Settings.Save()
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Show()
End Sub
Private Sub ExcluirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExcluirToolStripMenuItem.Click
lstbox_sitelist.Items.RemoveAt(lstbox_sitelist.SelectedIndex)
End Sub
Private Sub AbrirTodosToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirTodosToolStripMenuItem.Click
For i = 0 To lstbox_sitelist.Items.Count
Try
Process.Start(lstbox_sitelist.Items(i))
Catch ex As Exception
MsgBox(ex)
End Try
Next
End Sub
Private Sub SairToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem1.Click
Me.Dispose()
End Sub
consegui resolver ^^ vlw galera ^^ só que com timer num deu tive que fazer assim memo
Tópico encerrado , respostas não são mais permitidas