Charger combobox à partir fichier txt

Résolu
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014 - 6 déc. 2013 à 08:52
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014 - 6 déc. 2013 à 23:26
Bonjour,
http://codes-sources.commentcamarche.net/source/62667-charger-un-combobox-ou-une-listbox-a-partir-d-un-fichier-et-vice-versa

j'ai trouve ce code sur le forum
J'ai un problème avec endofstream
(N'appartient pas à streamreader)
Quelqu'un a une idée ?
Merci

11 réponses

ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
6 déc. 2013 à 09:29
Bonjour,
http://msdn.microsoft.com/fr-fr/library/system.io.streamreader.endofstream%28v=vs.110%29.aspx
où tu constates que reconnu par :
".NET Framework
Pris en charge dans : 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client Profile
Pris en charge dans : 4, 3.5 SP1
Bibliothèque de classes portable
Pris en charge dans : Bibliothèque de classes portable
.NET pour les applications du Windows Store
Pris en charge dans : Windows 8
"
0
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014
6 déc. 2013 à 11:02
Bonjour ucfutu,

je l'ai déja lu ce lien ...
j'ai framework 3.5

dois je declarer ? Et ou ?
Public ReadOnly Property EndOfStream() As Boolean

il me met EndOfStreaml n'est pas un membre de system.io.streamreader ...
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
Modifié par ucfoutu le 6/12/2013 à 11:30
Je ne connais personnellement rien à VB.Net (désolé, mais moi, je développe sous VB6)
Je jurerais cependant que tu as omis d'importer System.io

________________________
Réponse exacte ? => "REPONSE ACCEPTEE" facilitera les recherches.
Pas d'aide en ligne installée ? => ne comptez pas sur moi pour simplement répéter son contenu. Je n'interviend
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
6 déc. 2013 à 12:15
Bonjour,

Voilà avec une listBox1 et un fichier texte nommé" Fichier" placé dans le dossier Debug de l'application:

 Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SaveListBox(ListBox1, Application.StartupPath & "\Fichier.txt")
End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadListBox(ListBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Public Sub LoadListBox(ByRef oLst As System.Windows.Forms.ListBox, ByVal sPath As String)
Dim sr As New System.IO.StreamReader(sPath)
Do While Not sr.EndOfStream
oLst.Items.Add(sr.ReadLine())
Loop
sr.Close()
End Sub
Public Sub SaveListBox(ByRef oLst As System.Windows.Forms.ListBox, ByVal sPath As String)
Dim sw As New System.IO.StreamWriter(sPath)
For Each o As Object In oLst.Items
sw.WriteLine(o.ToString)
Next
sw.Close()
End Sub


bonjour ucfoutu
System IO est déclaré là:
Dim sw As New System.IO.StreamWriter(sPath)

bonne journée
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014
6 déc. 2013 à 14:38
bonjour,

J'ai en fait ce code
Mais le pbl vient de la ligne
Do While Not sr.EndOfStream
EnfOfStream n'est pas un membre du system.io.streamreader
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
6 déc. 2013 à 15:01
Je n'avais pas vu que c'était un comboBox. Ce code fonctionne chez moi. Pour ajouter un élément dans le combo et qu'il soit enregistré dans le fichier texte il faut procéder avec un texteBox et un button comme ceci:

Public Class Form1
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SaveListBox(ComboBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
LoadListBox(ComboBox1, Application.StartupPath & "\Fichier.txt")
End Sub
Public Sub LoadListBox(ByRef oLst As System.Windows.Forms.ComboBox, ByVal sPath As String)
Dim sr As New System.IO.StreamReader(sPath)
Do While Not sr.EndOfStream
oLst.Items.Add(sr.ReadLine())
Loop
sr.Close()
End Sub
Public Sub SaveListBox(ByRef oLst As System.Windows.Forms.ComboBox, ByVal sPath As String)
Dim sw As New System.IO.StreamWriter(sPath)
For Each o As Object In oLst.Items
sw.WriteLine(o.ToString)
Next
sw.Close()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)
End Sub
End Class
0
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014
6 déc. 2013 à 17:27
Bonjour pivert

En fait j'ai deja ce code.
J'ai le même à l'identique
Mais j'ai tjrs ce pbl avec ce EnfOfStream qui n'est pas un membre du system.io.streamreader

Qu'as tu mis dans imports ?
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
6 déc. 2013 à 18:16
Comme tu peux le voir, je n'ai rien mis. Ouvre un nouveau projet et mets ce code. Cela doit fonctionner. Il y a peut-être dans ton projet un Import qui est en conflit.
0
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014
6 déc. 2013 à 18:24
idem avec un nouveau projet ...
Pff quel galere
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
Modifié par ucfoutu le 6/12/2013 à 18:30
Fais cet essai :
Dans un nouveau projet :
reprends le code que tu trouveras là :
http://msdn.microsoft.com/fr-fr/library/system.io.streamreader%28v=vs.110%29.aspx
remplace les écritures sur la console par des msgbox
dis-nous ce qui se passe alors ainsi.

________________________
Réponse exacte ? => "REPONSE ACCEPTEE" facilitera les recherches.
Pas d'aide en ligne installée ? => ne comptez pas sur moi pour simplement répéter son contenu. Je n'interviend
0
collargol123 Messages postés 86 Date d'inscription jeudi 24 octobre 2013 Statut Membre Dernière intervention 2 avril 2014
6 déc. 2013 à 23:26
Bon apres plusieurs tentatives, j'ai eu tjrs le même probleme

J'ai finalement trouvé ce code qui fonctionne parfaitement bien pour la lecture : http://www.dreamincode.net/forums/topic/205857-edit-and-replace-from-text-file-vbnet/

Dim file As System.IO.File
Dim reader As System.IO.StreamReader
Dim line As String
reader = file.OpenText(bou)
'now loop through each line
While reader.Peek <> -1
line = reader.ReadLine()
oLst.Items.Add(line)

End While

'close your reader

reader.Close()
0
Rejoignez-nous