locked
Load data from DataSet into ListView Control?

    Question

  • I have an Access database and am saving data from a ListView control to the database.  This works great.  I cannot seem to figure out how to load the data from the database INTO the ListView though when I need to do this... 

    Basically, the data in the database looks like this:

    item1, item2, item3, item4, item5, item6

    When I load it into the ListView I want to remove the "," and have each item its own item in the ListView.  The items could be multiple words as well.  They are separated by "," though.

    I can access the database and load the data into the dataset, I just don't know how to take the data from the dataset and put it in the ListView...  I was able to find an article online, but the example didn't work...

    Would someone be able to tell me how I can do this?  I am very curious how this might be done.

    Thank you again.
    Saturday, January 05, 2008 1:29 AM

Answers

  •  

    so you know how to get the data from the database, and that data is presented to you in the form of a string. you want to take every element of that string (elements are separated by commas) and display it on a listview. this is the way you can achive this goal:

     

    Code Block

    string s = "item1, item2, item3, item4, item5, item6";

    string[] word = s.Split(new Char[] { ',' });

    foreach (string data in word)

    {

    listView1.Items.Add(data);

    }

     

     

    Saturday, January 05, 2008 1:48 AM

All replies

  •  

    so you know how to get the data from the database, and that data is presented to you in the form of a string. you want to take every element of that string (elements are separated by commas) and display it on a listview. this is the way you can achive this goal:

     

    Code Block

    string s = "item1, item2, item3, item4, item5, item6";

    string[] word = s.Split(new Char[] { ',' });

    foreach (string data in word)

    {

    listView1.Items.Add(data);

    }

     

     

    Saturday, January 05, 2008 1:48 AM
  • Thank you so very much for your response.  That did the trick perfectly.  Smile

    Thank you again.
    Saturday, January 05, 2008 2:46 AM