Hello,

Before anything, I want to say that I will keep looking around, but im leaving this thread here to possible get faster answers and solutions.

Well, I'm trying to save multiple texts from textboxes and comboboxes, and after saving the information to a file an item will be added to a ListView, so example if i have 3 "Users" information i can go back to the information by clicking the ListView item.

And when i close/open the application the information will be loaded already to the listview and such, but first i just need to figure what was mentioned above first, the second part i think will be much easier to handle, as of now im unsure as where to start.

Fist you need to decide on your data structure. This is entirely up to you, but personally, XML makes things readable and organised.

System.Xml and System.Xml.XPath will be your friend ;)

An example structure for you might be;

<?xml version="1.0" standalone="yes" ?>
<DataItems>
    <Item>
        <Age>20</Age>
        <Sex>M</Sex>
        <TextComment>Likes stuff</TextComment>
    </Item>
</DataItems>

Or you can use generic tags with an attribute to describe which combo box it is. Either way, your virtual object should be easy to understand.

You can read/write to file using the built in mechanisms for the Xml Documents.

In addition, if you switch to a datagridview with a datatable as datasource you can present your information and the datatable can read and write the information to and from an xml file.

Yeah i was looking around and the most things pointed to XML, The problem im having is loading it to the listview and get information from it.

E.g: ListView contains 2 columns "Name" and "Age", and every person that i saved is loaded in the listview.

When i click E.g: "iFrolox" all the information is loaded on the controls, when i click "Ketsuekiame" all the information for that name is loaded to the controls.

Are you using WPF or WinForms? WPF makes this easier, but the same can be achieved in WinForms. You can use DataBinding. So you can take an array of your objects, format them in a specific way and then have your control display them.

When your item is selected, your other controls will be bound to specific properties of that object, allowing them to display the information you requested.

WinForms

the MSDN contains far more information than I could post here. But I feel that DataBinding is exactly what you need. :)

Alright, I'll look into DataBinding tomorrow, i need some good sleep. Hopefully you're right about that beign exactly what i need, thank you.

Well i've been looking around, and it seems like that's what I'm looking for, but I still have no clue how to load every account to a listview and be able to change through accounts by clicking a different item in the listview.

But this is how im saving just the names so far:

        Users dtUsers = new Users();
        String XMLlocation = Application.StartupPath + @"\XMLUsers.xml";

        private void save_Click(object sender, EventArgs e)
        {
            DataTable dtTable = dtUsers.Tables["Information"];
            DataRow dtRow = dtTable.NewRow();

            dtRow["Name"] = this.iName.Text;
            dtTable.Rows.Add(dtRow);
            dtTable.WriteXml(XMLlocation);
        }

        private void load_Click(object sender, EventArgs e)
        {
        BindingSource bsource = new BindingSource();

        dtUsers.ReadXml(XMLlocation);

        bsource.DataSource = dtUsers;
        bsource.DataMember = dtUsers.Tables[0].TableName;

        iName.DataBindings.Add("Text", bsource, "Name");

        }

You will need to hook into the controls OnClick on OnItemSelected (I can't remember which it has off-hand) event. That way you will be given the item data or a way to retrieve the item data (item id etc). With this information you can update the other controls.

Solved it, using List<t>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.