Thumbs upSolvedSaving/Editing/Removing ComboBox Data

Posts 1–15 of 22 · Page 1 of 2
Saving/Editing/Removing ComboBox Data
I'm making a program to save information for what data I have one disc's I have burned.

Basically, what I am doing is I title a disc and burn the pictures/videos on to the dvd, then I want to create a item in a combo box with that name and then I will have a text box show the names of the videos/pictures that I want on in the disc.

The problem is, I need the items to save in the combo box so that when I restart the programs, the items will still be there. I also would like to have an option to edit the names in case if I decide to change it, and if I decide to remove an item because maybe the disc broke or I made a new one with a different name, I would like to remove that item from the combo box.

A few ways to do this is using my.settings or using an XML file. My.settings never seems to save when I move my program or copy it to another location. So I would like to use a XML file, though I have never used an XML file nor do I know how to add and remove data from it. Anyone mind explaining how to do so?

This is kinda the idea of the program, though I'm probably going to change some things around:


I've found an example on CodeProject, http://www.codeproject.com/Articles/...ove-Create-XML

I have figured out how to add items to xml and read it. The only thing is, when the program loads, it only adds the most recent item from the XML file to the combo box.

So this is what I am using:
Code:
Dim read As String
        read = Read_XML_Value_("\DiscInfo\Disc.xml", "/Root/", "Name")
        discsel.Items.Add(read)
It just reads the first item off of the Root and adds it. So maybe I would have to create my own items after the root, but then I would have to load every item after that, and I would have to save every one separately, so I'm out of ideas.. any help?
You can also use .ini files to save info

API: WritePrivateProfileString, GetPrivateProfileString
Quote Originally Posted by Biesi View Post
You can also use .ini files to save info

API: WritePrivateProfileString, GetPrivateProfileString
Yea, but ini files are more for settings... XML's are more for data. But really confusing ._.
Simple.

Read from the .xml file you're wanting to use. Also, save as a list where you would be able to read/write to; to later save the data back into the .xml file.
To edit, just edit the item of the list via the index of the item.
Quote Originally Posted by DawgiiStylz View Post
Simple.

Read from the .xml file you're wanting to use. Also, save as a list where you would be able to read/write to; to later save the data back into the .xml file.
To edit, just edit the item of the list via the index of the item.
I have that idea down.. stated in op. I'm stuck on how to load multiple items from an xml.
Code:
dim xdoc as xdocument = xdocument.load(path)

For Each xel In xdoc.Elements()(0).Elements()
   '###
Next
Code:
<whatever>
	<item>item1</item>
	<item>item2</item>
	<item>item3</item>
</whatever>
Quote Originally Posted by Biesi View Post
Code:
dim xdoc as xdocument = xdocument.load(path)

For Each xel In xdoc.Elements()(0).Elements()
   '###
Next
Code:
<whatever>
	<item>item1</item>
	<item>item2</item>
	<item>item3</item>
</whatever>
This would work... but when the XML saves with the same item name, it replaces the original one..

But, I'll try some things when I get home. Do you have a method for saving to XML's as well?
Quote Originally Posted by Cryptonic View Post
Do you have a method for saving to XML's as well?
Xml.XmlTextWriter
Quote Originally Posted by Biesi View Post


Xml.XmlTextWriter
Can you explain how to use this?

Only thing I got so far is Xml.XmlTextWriter.Create("C:\test.xml") o_o

This page wasn't too helpful - XmlTextWriter Class (System.Xml)

I also tried another code

Code:
Dim writer As New XmlTextWriter(directory, Nothing)
            writer.WriteStartElement("items")
            writer.WriteElementString("name", TxtBox1.Text)
            writer.WriteEndElement()
            writer.Close()
But that replaces the same item as well.
Quote Originally Posted by Cryptonic View Post
Can you explain how to use this?
Code:
dim enc as new system.text.unicodeencoding
dim xwriter as new xml.xmltextwriter(directory, enc)

with xwriter
  .writestartdocument()
  .writestartelement("whatever") '<whatever>
  .writestartelement("item") '<item>
  .writevalue("item1") 'item1
  .writeendelement() '</item>
  .writestartelement("item") '<item>
  .writevalue("item2") 'item2
  .writeendelement() '</item>
  .writeendelement() '</whatever>
  .close()
end with
something like that
Quote Originally Posted by Biesi View Post


Code:
dim enc as new system.text.unicodeencoding
dim xwriter as new xml.xmltextwriter(directory, enc)

with xwriter
  .writestartdocument()
  .writestartelement("whatever") '<whatever>
  .writestartelement("item") '<item>
  .writevalue("item1") 'item1
  .writeendelement() '</item>
  .writestartelement("item") '<item>
  .writevalue("item2") 'item2
  .writeendelement() '</item>
  .writeendelement() '</whatever>
  .close()
end with
something like that
Wouldn't that do the same as the other code I'm using? I'm trying to have an unlimitied ammount of values that can be entered by a user into an XML file. Then that data can be read when the program starts and entered it into the comx (damnit bo bo, go away >:O. Should be combo box). The thing is, if every name is different, you have to load it all seperatly (unless there's a way to do that).

Sorry if this is confusing, I'm trying to think this out while I'm at school

Thanks for all of your help so far.
Well, this won't be of much help and it's my first XML usage code.
It append "items" and add them attributes:
 
Nooby Code


I'll see if I can make something for you in the mean time
Quote Originally Posted by Jorndel View Post
Well, this won't be of much help and it's my first XML usage code.
It append "items" and add them attributes:
 
Nooby Code


I'll see if I can make something for you in the mean time
This is what it created with that code
This was something I did for an application, I probably wrote alot more then was really needed but I couldn't seem to get saving and resaving an xml file to work properly any other way.

Saving the file
Code:
    Private Sub saveCleaningLocations(ByVal folderPath As String)


        Dim writestart As Boolean


        'If file doesnt exist then set write to true

        If IO.File.Exists("CleaningLocations.xml") Then
            Dim currentXMLDocument As New XmlDocument
            currentXMLDocument.Load("CleaningLocations.xml")

            Dim parentNode As XmlNode = currentXMLDocument.SelectSingleNode("Locations")

            Dim prodnode As XmlNode = currentXMLDocument.CreateNode(XmlNodeType.Element, "FolderPath", "")

            prodnode.InnerText = folderPath
            parentNode.AppendChild(prodnode)
            currentXMLDocument.Save("CleaningLocations.xml")

        Else
            writestart = True
            Dim xmlFile As IO.FileStream = New IO.FileStream("CleaningLocations.xml", IO.FileMode.Append)
            Dim xmlTextWriter As New XmlTextWriter(xmlFile, System.Text.Encoding.Default)
            With xmlTextWriter
                .Formatting = Formatting.Indented
                .Indentation = 3
                .IndentChar = CChar(" ")
                If writestart Then .WriteStartDocument()

                .WriteStartElement("Locations")
                .WriteElementString("FolderPath", folderPath)
                .WriteFullEndElement()
                .Close()

            End With

        End If
        databind()
    End Sub
Reading in the file
Code:
  Private Sub ReadCleaningLocations()

        If IO.File.Exists("CleaningLocations.xml") Then
            Dim documentClean As XmlReader = New XmlTextReader("CleaningLocations.xml")
            While (documentClean.Read())
                Dim type = documentClean.NodeType

                If type = XmlNodeType.Element Then
                    If documentClean.Name = "FolderPath" Then
                        CreateRows(documentClean.ReadInnerXml.ToString)
                    End If
                End If
            End While
            documentClean.Close()
        End If
    End Sub
This was a copy and paste right from my app so you may have to pick what you need out of it, but as it is, it's working code
I have no idea how you're banned, but if you're not permanently banned, you used this for saving folder locations? And what did you insert the data to, a listbox?
Posts 1–15 of 22 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us