Dim line As String
Dim reader As System.IO.StreamReader
If Not IO.File.Exists(sPath)Then
Exit Sub
End If
reader = IO.File.OpenText(sPath)
'now loop through each line
While reader.Peek <> -1
line = reader.ReadLine()
Combobox1.Items.Add(line)
End While
'close your reader
reader.Close()
Dim reader As New System.IO.StreamReader(spath, System.Text.Encoding.UTF8)
Imports System.IO
Imports System.Text
Public Sub LoadComboBox(ByRef oLst As System.Windows.Forms.ComboBox, ByVal sPath As String)
Dim line As String
Dim reader As StreamReader = New System.IO.StreamReader(sPath, Encoding.Default)
If Not File.Exists(sPath) Then
Exit Sub
End If
reader = File.OpenText(sPath)
'now loop through each line
While reader.Peek <> -1
line = reader.ReadLine()
oLst.Items.Add(line)
End While
'close your reader
reader.Close()
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionLoadComboBox(ComboBox1,"C:\ chemin \Fichier.txt")
'mettre le nom de ton combo
ComboBox1.Items.Clear()
ComboBox1.Items.AddRange(System.IO.File.ReadAllLines(Application.StartupPath & "\Fichier.txt"))