ich glaub ich habs selber schon rausgefunden.
Da steht ja im Fehler das das nicht geht weil die datasource eigenschafft bei der Listbox aktiviert ist.
Aber diese muss ja aktiviert sein sonst funktioniert der openfiledialog nicht mehr..
Ich habe auch schon dieses Code ausprobiert
Code:
Public Sub ListBox_Save(ByVal ListBox As ListBox, _
ByVal sFile As String)
' Inhalt einer ListBox speichern
Dim oStream As IO.StreamWriter
Dim i As Short
oStream = New IO.StreamWriter(sFile)
For i = 0 To ListBox.Items.Count - 1
oStream.WriteLine(ListBox.Items(i))
Next
oStream.Close()
End Sub
Public Sub ListBox_Read(ByVal ListBox As ListBox, _
ByVal sFile As String)
' Inhalt einer ListBox speichern
Dim oStream As IO.StreamReader
Dim sLine As String
' ListBox löschen
ListBox.Items.Clear()
' Existsiert die Datei?
Dim oFile As New IO.FileInfo(sFile)
If oFile.Exists() = True Then
oStream = New IO.StreamReader(sFile)
' Datei zeilenweise auslesen
Do
sLine = oStream.ReadLine()
If IsNothing(sLine) Then Exit Do
ListBox.Items.Add(sLine)
Loop
oStream.Close()
End If
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdSave.Click
' ListBox speichern
Dim sFile As String
sFile = Application.StartupPath & "\Liste.dat"
ListBox_Save(ListBox1, sFile)
End Sub
Private Sub cmdClear_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdClear.Click
' Inhalt der ListBox löschen
' (dient nur zur besseren Demonstration)
ListBox1.Items.Clear()
End Sub
Private Sub cmdRead_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdRead.Click
' ListBox einlesen
Dim sFile As String
sFile = Application.StartupPath & "\Liste.dat"
ListBox_Read(ListBox1, sFile)
End Sub
und da kahm der gleiche Fehler.
Heißt das dann man kann grundsetzlich nicht den inhalt einer listbox speichern wenn da bei datasource eigenschafft aktiviert ist?