Ouvrir un fichier texte dans une listbox

Résolu
Logileman Messages postés 30 Date d'inscription mardi 27 mars 2012 Statut Membre Dernière intervention 4 juillet 2012 - 4 juil. 2012 à 10:28
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 - 4 juil. 2012 à 13:25
Bonjours,
Comment ouvrir un fichier texte (.txt) dans une listbox avec une openfiledialog ?
Merci d'avance

1 réponse

cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
4 juil. 2012 à 13:25
Salut

Private Sub ReadAllFile(ByVal path As String)
        Try
            ListBox1.Items.Clear()
            ListBox1.Items.AddRange(System.IO.File.ReadAllLines(path).ToArray)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Private Sub Buttontest_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttontest.MouseClick
        OpenFileDialog1.ShowDialog()
    End Sub

Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        If e.Cancel = True Then Exit Sub
        ReadAllFile(DirectCast(sender, OpenFileDialog).FileName)
    End Sub
3
Rejoignez-nous