locked
Read Values from CSV and Bind Combobox Selection to IDs

    Question

  • Hi, 

    I have a pipe-delimited CSV with the following values: 

    SEID|Name
    0001|"Larry the Cucumber"
    0002|"Bob the Tomato"

    I need to read the values from the file and then display only the name in a combobox. When a value from the combobox is selected, I then need to save the selected name but by its ID (and not by converting the selected value to a string). 

    To go about this, I had the following: 

    public class peopleList
            {
                public int ID { get; set; }
                public string name { get; set; }
            }
    
    List<peopleList> theList = new List<peopleList>();
                var peoplePath = Path.Combine(Package.Current.InstalledLocation.Path, "Assets/people.csv");
    

    My idea was to then display the list names in the combobox and when the selection in combobox changed, it would get the ID based on the selected name. 

    I found several different ways to read in the values, but none of them seemed to work in Visual Studio. How can I read the files? Is there a different way I should go about doing this? 

    Any advice you have would be helpful. Thanks.

    Thursday, July 17, 2014 3:27 PM

Answers

  • This is what you use to read text from a file:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileio.readtextasync.aspx


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, July 17, 2014 5:48 PM
    Moderator
  • Read a line into a string, use string.split("|").


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, July 18, 2014 5:50 PM
    Moderator

All replies

  • This is what you use to read text from a file:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileio.readtextasync.aspx


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, July 17, 2014 5:48 PM
    Moderator
  • Thanks. How would I read through the file line-by-line splitting it into parts when it encounters the | delimiter?
    Thursday, July 17, 2014 8:09 PM
  • Read a line into a string, use string.split("|").


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, July 18, 2014 5:50 PM
    Moderator