Results 1 to 8 of 8

Thread: [RESOLVED] ListView Wordwrap

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Resolved [RESOLVED] ListView Wordwrap

    Hi and thanks for reading,

    Is it possible to make the ListView control "wordwrap" in VB.Net so that any rows that have item text that is too long to be displayed fully are wordwrapped (i.e. increased in height) so that all of their data is displayed?

    Thanks!

    OneSource

  2. #2
    New Member
    Join Date
    May 2006
    Posts
    3

    Re: ListView Wordwrap

    How to make wordwrap in listview in vb.net. I need the source code for wordwrapping in listview in vb.net. Please help me in providing the source code for that.
    Thank you,

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ListView Wordwrap

    Can't be done without owner drawing as far as I'm aware. Your best bet is to set ShowItemToolTips to True and then the user can mouse over a string that is cut off to show the whole string in a tool tip.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    New Member
    Join Date
    May 2006
    Posts
    3

    Re: ListView Wordwrap

    If it is possible wordwrapping in datagrid why not is possible in listview.Please search for the code as early as possible. I need it badly. Or how can I display lengthy text that we can view not by dragging.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ListView Wordwrap

    If I can milk a cow then why can't I milk a tractor? They both can pull a plough.

    The ListView is a completely different class to the DataGrid. The fact that one can do something means absolutely nothing about the other one.

    You have the same access to resources that I do. The following link was provided on the second page of results from a Google search for "wordwrap listview" (without quotes). The code is C# but you can reference the assembly directly from your VB app or use a code converter like those in my signature.

    http://www.codeproject.com/cs/miscct...asp?print=true
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    New Member
    Join Date
    May 2006
    Posts
    3

    Re: ListView Wordwrap

    Please give me the source code for datagrid wordwrap.I need to take information from the 2 text files. Each para in text file should be stored in each cell of datagrid in seperate column so that all the lengthy text should be visible. Please help me sending source code. do not direct me to codeguru.com where I'm not able to login.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ListView Wordwrap

    I didn't direct you to Code Guru, I directed you to The Code Project, which is one of the most important Web sites around for .NET developers. If you can't log in there then create a user account so you can. I just went to Google again and searched for "wordwrap datagrid" (without quotes) and the fourth result returned was a link to The Code Project that explains how to do just what you want. As I said, we all have access to the same resources. If I can find this stuff then you can too. We're here to help, not do everything for you. If you find this stuff and don't understand it then that's a different story, but you're just as capable as I am of finding it in the first place.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    New Member
    Join Date
    Oct 2015
    Posts
    1

    Re: ListView Wordwrap

    Ive also looked for means on wrapping item text in a listview and came up short handed, I tried using ColumnHeaderAutoResizeStyle.HeaderSize property, and it works until you start scrolling. I also tried hiding the horizontal scrollbar using a ScrollListener class. But unfortunately the column would keep resizing to the size of the text. and the horizontal scrollbar would reappear Luckily I came up w an idea to wrap the text myself and it worked w no problem

    PS. Its also a good idea to keep the original text in the Items().Tag property, that way you can always use it to refer to the original text

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    For i = 0 To 10
    Dim Item As New ListViewItem
    Item.Text = "blah"
    Item.SubItems.Add(StrLabelWrap("xxxxxxxxxxxxxxxxxxx", LV.Font, LV.Columns(1).Width - 10))
    Item.SubItems(1).Tag = "xxxxxxxxxxxxxxxxxxx"
    LV.Items.Add(Item)
    Next
    End Sub

    Private Sub LV_ColumnWidthChanged(sender As Object, e As _ ColumnWidthChangedEventArgs) Handles LV.ColumnWidthChanged
    For i = 0 To LV.Items.Count - 1
    If LV.Items(i).SubItems(1).Text <> StrLabelWrap(LV.Items(i).SubItems(1).Tag, LV.Font, LV.Columns(1).Width - 10) _
    Then LV.Items(i).SubItems(1).Text = StrLabelWrap(LV.Items(i).SubItems(1).Tag, LV.Font, LV.Columns(1).Width - 10)
    Next
    End Sub

    Public Function StrLabelWrap(strText As String, xFont As Font, intWidth As Integer) As String
    If strText = "" Then Return Nothing
    if intWidth = 0 then Return Nothing
    Dim i As Integer, textSize As Size = TextRenderer.MeasureText(strText, xFont)
    StrLabelWrap = strText
    If textSize.Width > intWidth Then
    For i = 1 To strText.Length
    textSize = TextRenderer.MeasureText(strText.Substring(0, i) & "...", xFont)
    If textSize.Width < intWidth _
    Then StrLabelWrap = strText.Substring(0, i) & "..."
    Next
    End If
    Return StrLabelWrap
    End Function

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