CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2012
    Posts
    4

    list box problem

    Hi friends,

    I want to put a long string in list box, which its width is more than width of list box.This is my problem:I want to put this long string in multiple lines
    instead of using horizontal scroll.I mean when the string exceeds the end of line, it should back to the first of the next line.

    Thanks

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: list box problem

    Standard list box does not support this multiline behavior.
    You can:
    • Use owner drawn control and implement your custom multiline rendering, or
    • Show a tooltip window while hovering over the long entry
    Best regards,
    Igor

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: list box problem

    And here is an example of Multi-Line ListBox
    Victor Nijegorodov

  4. #4
    Join Date
    Aug 2012
    Posts
    4

    Re: list box problem

    Thank you for your helpful answers.
    There is no difference for me to use list box or something else.
    Is there an easier way to approach the mentioned purpose?
    (show a long string in a small box)

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: list box problem

    I guess this multi-line list implementation would met your needs.
    http://www.codeproject.com/Articles/...e-List-Control
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: list box problem

    Does it really need to be a list box? Do you need to select the different entries? An Edit or a Static control will display and wrap the text for you.

  7. #7
    Join Date
    Aug 2012
    Posts
    4

    Re: list box problem

    As I said before, there is no importance to use listbox or editbox or ...
    I just need a small box to show a long string.for example this is my string :

    str="Hello World! Hello World!";

    my edit/list box isn't wide enough to show whole the string, so it just shows : Hello World! He
    I want the result to be something like this:
    Hello World!
    Hello World!

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: list box problem

    Then use multiline style for the edit control (ES_MULTILINE) and if you'd like to allow user to set/change control text - additionally specify ES_WANTRETURN.
    Victor Nijegorodov

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: list box problem

    Quote Originally Posted by moottii View Post
    my edit/list box isn't wide enough to show whole the string, so it just shows : Hello World! He
    I want the result to be something like this:
    Hello World!
    Hello World!
    Then you could format the text using CRLF to achieve line breaks for both edit () and static controls:
    Code:
    m_myControl.SetWindowText(_T("Hello World!\r\nHello World!"));
    where m_myControl is a control member variable of the control
    Victor Nijegorodov

  10. #10
    Join Date
    Aug 2012
    Posts
    4

    Re: list box problem

    Thanks for you reply.
    But unfortunately I don't know what my string is."Hello World!Hello World!" was an example.
    In fact I'm writing a packet sniffer and I wanna show whole the data of each packet, into a separated box(this critical box)
    So i'm not able to use that
    m_myControl.SetWindowText(_T("1st part of string\r\n 2nd part of string"));
    for going to the next line.

  11. #11
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: list box problem

    Quote Originally Posted by moottii View Post
    Thanks for you reply.
    But unfortunately I don't know what my string is."Hello World!Hello World!" was an example.
    In fact I'm writing a packet sniffer and I wanna show whole the data of each packet, into a separated box(this critical box)
    So i'm not able to use that
    m_myControl.SetWindowText(_T("1st part of string\r\n 2nd part of string"));
    for going to the next line.
    As I said, an edit or static control will wrap for you.

  12. #12
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: list box problem

    http://msdn.microsoft.com/en-us/libr...rap_linebreaks
    An application can use Wordwrap functions with multiline edit controls to locate the word or word fragment that should be wrapped to the next line. Using the default Wordwrap function provided by the system, lines always end at the spaces between words. An application can specify its own Wordwrap function by supplying an EditWordBreakProc Wordwrap function and sending the edit control an EM_SETWORDBREAKPROC message. An application can retrieve the address of the current Wordwrap function by sending the control an EM_GETWORDBREAKPROC message.
    How do you use the default word wrapping for an edit control?
    If you do not specify ES_AUTOHSCROLL, the control automatically wraps words to the beginning of the next line when necessary. A new line is also started if the user presses the ENTER key. The window size determines the position of the Wordwrap. If the window size changes, the Wordwrapping position changes and the text is redisplayed.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

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