Elikäs ohjelmassani on kaksi eri comboboxia joihin lisätään ja poistetaan tuottenimiä kahdella buttonilla. Tarkoitus olisi, että käytön jälkeen ohjelman suljettaessa close napilla kummankin comboboxin sen käyttökerran aikana lisätyt/poistetut tiedot tallentuisivat. En halua siis mitään koko ohjelman tietojen tallennusta sillä ohjelman muiden tietojen ei tarvitse säilyä, ainoastaan comboboxien.
Muuten hyvä, mutta linkissä on pitkälti neuvoja .txt tiedostojen tallentamiseen, eikä niinkään ohjelman itsessään päivitykseen. Jaa niin ja unohtuikin topicista, että pohjana on VB.Net.
Moikka moks!
vääntele oheisesta esimerkistä mielesi mukainen viritelmä
Public Class MainForm
Public Shared WithEvents cboCollection As New Collection()
'...
'...
Sub MainFormLoad(sender As Object, e As EventArgs)
Dim exists As Boolean = (Dir("C:\cbodata.dat") <> "")
If exists Then
FileSystem.FileOpen(1, "C:\cbodata.dat", OpenMode.Input)
Do While Not EOF(1)
Dim fstr As String = ""
FileSystem.Input(1,fstr)
comboBox1.Items.Add(fstr.Replace(Environment.NewLine,""))
Loop
FileSystem.FileClose(1)
End If
If comboBox1.Items.Count > 0 Then
comboBox1.SelectedIndex = 0
End If
End Sub
Sub Button1Click(sender As Object, e As EventArgs)
If textBox1.Text <> "" Then
comboBox1.Items.Add(textBox1.Text)
comboBox1.SelectedIndex = comboBox1.Items.Count - 1
'If Not IsExisting(textBox1.Text) Then
cboCollection.Add(comboBox1.SelectedItem.ToString())
'End If
textBox1.Text = ""
End If
End Sub
Sub Button2Click(sender As Object, e As EventArgs)
If comboBox1.Items.Count = 1 Then
'If Not IsExisting(comboBox1.Items(0).ToString()) Then
cboCollection.Add(comboBox1.Items(0).ToString())
'End If
comboBox1.Items.Remove(comboBox1.Items(0).ToString())
comboBox1.Text = ""
Else If comboBox1.Items.Count > 1 Then
'If Not IsExisting(comboBox1.Items(0).ToString()) Then
cboCollection.Add(comboBox1.SelectedItem.ToString())
'End If
comboBox1.Items.Remove(comboBox1.SelectedItem.ToString())
comboBox1.SelectedIndex = comboBox1.Items.Count - 1
End If
End Sub
Sub Button3Click(sender As Object, e As EventArgs)
Dim i As Integer = 0
FileSystem.FileOpen(1, "C:\cbodata.dat", OpenMode.Output)
If cboCollection.Count > 0 Then
For i = 1 To cboCollection.Count
FileSystem.Print(1, cboCollection.Item(i).ToString _
+ Environment.NewLine)
Next
End If
FileSystem.FileClose(1)
Me.Close
End Sub
Function IsExisting(cbostring As String) As Boolean
If cboCollection.Count > 0 Then
Dim i As Integer = 0
For i = 1 To cboCollection.Count
If cboCollection.Item(i) = cbostring Then
Return True
Exit Function
End If
Next
End If
Return False
End Function
Sub MainFormFormClosing(sender As Object, e As FormClosingEventArgs)
Me.Dispose
End Sub
Sub MainFormFormClosed(sender As Object, e As FormClosedEventArgs)
End
End Sub
End ClassEn ole päässyt vielä kokeilemaan, mutta kiitoksia!
Aihe on jo aika vanha, joten et voi enää vastata siihen.