Results 1 to 24 of 24

Thread: [RESOLVED] ListView

  1. #1

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Resolved [RESOLVED] ListView

    I have the attached result in ListView and would like to separate the words by commas to make them readable. Can code be added to do this and if so where? Thanks for any help.


    Name:  listview.JPG
Views: 243
Size:  18.7 KB

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: ListView

    What commas?
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: ListView

    you could use regex.
    do you have a list of the unique (distinct) words that each listviewitem might contain?

    also... that looks more like a listbox than a listview

  4. #4

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Quote Originally Posted by .paul. View Post
    you could use regex.
    do you have a list of the unique (distinct) words that each listviewitem might contain?

    also... that looks more like a listbox than a listview
    Name:  listview1.JPG
Views: 258
Size:  13.8 KB

    It is listview. The words can be any or all of those in the attachment.

  5. #5
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: ListView

    Looks like a separation at each Capitol Letter with the exception of Sci-Fi, hence leaving words that have hyphens alone - and treated as one word.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: ListView

    And there is also "Science Fiction" making things even more complicated. Before entering on how to create an AI that splits your words back, may I ask.. why are you adding them concatenated like that to the LV?

  7. #7

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Quote Originally Posted by jcis View Post
    And there is also "Science Fiction" making things even more complicated. Before entering on how to create an AI that splits your words back, may I ask.. why are you adding them concatenated like that to the LV?
    The info is extracted from an xml file

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: ListView

    can you post your code? there's got to be a simpler way, before you add the items to the listview

  9. #9
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: ListView

    Quote Originally Posted by .paul. View Post
    can you post your code? there's got to be a simpler way, before you add the items to the listview
    I agree. I would not like to see a Listview used in this way anyhow

  10. #10

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Here is the code:

    code.txt

  11. #11
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: ListView

    Can you attach the movie.xml file this program of yours operates with?

  12. #12

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Sample movie.xml attached

    movie.xml

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: ListView

    try this:

    vb Code:
    1. Dim lvi As New ListViewItem(xml.SelectSingleNode("Title/LocalTitle").InnerText)
    2. lvi.SubItems.Add(String.Join(", ", Array.ConvertAll(xml.SelectNodes("Title/Genres/Genre").Cast(Of XmlNode).ToArray, Function(n) n.InnerText)))

  14. #14

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Quote Originally Posted by .paul. View Post
    try this:

    vb Code:
    1. Dim lvi As New ListViewItem(xml.SelectSingleNode("Title/LocalTitle").InnerText)
    2. lvi.SubItems.Add(String.Join(", ", Array.ConvertAll(xml.SelectNodes("Title/Genres/Genre").Cast(Of XmlNode).ToArray, Function(n) n.InnerText)))


    Thanks that worked. However when I save to Excel, each Genre is in a separate column. Is there a way to have the same appearance as in listview or would I have to adjust manually?

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: ListView

    the problem is that you're saving your listview contents as excel CSV + the delimiter in a csv file is a comma.

    therefore excel sees that 1 field as several. use a semi colon ; instead of a comma:

    vb Code:
    1. Dim lvi As New ListViewItem(xml.SelectSingleNode("Title/LocalTitle").InnerText)
    2. lvi.SubItems.Add(String.Join("; ", Array.ConvertAll(xml.SelectNodes("Title/Genres/Genre").Cast(Of XmlNode).ToArray, Function(n) n.InnerText)))

  16. #16

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Quote Originally Posted by .paul. View Post
    the problem is that you're saving your listview contents as excel CSV + the delimiter in a csv file is a comma.

    therefore excel sees that 1 field as several. use a semi colon ; instead of a comma:

    vb Code:
    1. Dim lvi As New ListViewItem(xml.SelectSingleNode("Title/LocalTitle").InnerText)
    2. lvi.SubItems.Add(String.Join("; ", Array.ConvertAll(xml.SelectNodes("Title/Genres/Genre").Cast(Of XmlNode).ToArray, Function(n) n.InnerText)))
    Thanks. Works. Much appreciated.

  17. #17
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: ListView

    rate Paul OP and mark this thread as Resolved, please.
    TY

  18. #18

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Quote Originally Posted by proneal View Post
    rate Paul OP and mark this thread as Resolved, please.
    TY
    I hope I did that right.

  19. #19
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: ListView

    Well, Sir .Paul has an absolutely brilliant future of Rep points [2000+] -wow..
    I am sure you did it right, even though [RESOLVED] does not appear in Thread title.
    We will overlook this minor discrepancy...
    for now.
    mauahhahahaha



    good Luck OP!

  20. #20
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: ListView

    Quote Originally Posted by lag22 View Post
    I hope I did that right.
    you rated me. thanks

  21. #21
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Thumbs up Re: ListView

    Quote Originally Posted by proneal View Post
    Well, Sir .Paul has an absolutely brilliant future of Rep points [2000+] -wow..
    I am sure you did it right, even though [RESOLVED] does not appear in Thread title.
    We will overlook this minor discrepancy...
    for now.
    mauahhahahaha



    good Luck OP!
    + counting. thanks for that. i owe you a rating next time you post a good answer...

  22. #22

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    What is the correct way to mark Resolved?

  23. #23
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: ListView

    at the top right of your original question, there's a Thread Tools menu, which contains a Mark Thread Resolved menuitem

  24. #24

    Thread Starter
    Member
    Join Date
    May 2012
    Posts
    38

    Re: ListView

    Quote Originally Posted by .paul. View Post
    at the top right of your original question, there's a Thread Tools menu, which contains a Mark Thread Resolved menuitem
    Thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width