CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2007
    Location
    India
    Posts
    30

    Smile Split a long string data and display it in multiple lines of a ListView

    I want to display a long string that is fetched from the database in a ListView.
    As of now, the string is displayed in a single line of the ListView which makes it difficult to read the entire data.

    I want it to be displayed in multiple lines within the ListView.

    pls reply .... :-)

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Split a long string data and display it in multiple lines of a ListView

    There's probably a better way, but this seems to work...

    Code:
    String longstring = "aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd";
    String shortstring;
    
    for (int i = 0; i < longstring.Length; i += 10)
    {
        if ((i + 10) <= longstring.Length)
            shortstring = longstring.Substring(i, 10);
        else
            shortstring = longstring.Substring(i, (longstring.Length - i));
        listView1.Items.Add(shortstring);
    }
    It's not a bug, it's a feature!

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Split a long string data and display it in multiple lines of a ListView

    If it is a plain text without any metadata, then it makes no sence to display it in ListView. By what rule would you split it? Display it in TextBox with Multiline property set to true.
    Last edited by boudino; August 5th, 2008 at 01:43 AM. Reason: formatting
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Oct 2007
    Location
    India
    Posts
    30

    Wink Re: Split a long string data and display it in multiple lines of a ListView

    Dear foamy,

    In fact the string in question, is being fetched from a database and it comes within a Datatable. Moreover, I'm using MS Access file for this project.
    so I'm finding it difficult to split it in the way that u have suggested.

    so, if u know any other means by which the splitting can be done do let me know about that..

    thankyou :-)

  5. #5
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Split a long string data and display it in multiple lines of a ListView

    That shouldn't really matter... As long as you retrieve the string from somewhere.

    However, you should do as boudino suggested...
    It's not a bug, it's a feature!

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

Featured