mercredi 3 février 2016

Overwriting a saved setting in a CheckBox?

I have a small application that allows the user to check a custom number of CheckBoxes then save that to a ComboBox for selecting later. Right now the ComboBox accepts duplicates and I am trying to remove that and allow a user to overwrite their own particular saved selections. The data in each user's selection is stored first in a List(Of Tuple(Of String, List(Of String) called columnList, where item 1, accessed in a String called name, is the name of the list, and item 2 is the list. For access after closing the program it is also stored in a text file. I have a crude method that is supposed to allow the user to overwrite their own saved selections, where it removes the element at the location where the user's name is, then inserts it with the updated selections in the same place. I also have an int flag to tell the program if the user is overwriting rather than creating a new list.

For i = 0 To columnList.Count - 1
            If columnList(i).Item1 = name Then
                columnList.RemoveAt(i)
                columnList.Insert(i, Tuple.Create(name, customList))
                flag = 1
                Exit For
            End If
        Next
        If flag = 0 Then
            columnList.Add(Tuple.Create(name, customList))
        End If

The problem is that this is not deleting the data in the text file, rather adding another list of selections with a duplicate name to the file. So it works until you close the application, then when it reopens the original list is still displayed in the ComboBox along with the new list under a duplicate name at the bottom. I want to edit the storage text file directly from the application.




Aucun commentaire:

Enregistrer un commentaire