Windows Develop Bookmark and Share   
 index > Windows Forms General > multiline text in listview ?
 

multiline text in listview ?

Is there a easy way to enable multiple line / word wrapping height in a listviewitem inside a listview box on a winforms app?

I have LabelWrap set to true but it doesn't seem to work when in "Details" or "List" mode - only seems appropriate on icon labels.
MigrationUser 1  Monday, January 17, 2005 12:48 AM

Hi WinsFormsUser;
I had the same problem.....The only way I have found so far is by setting the OwnerDraw property and programatically setting the properties for the listviewitem... take a look at the OwnerDraw properties documentation.

Hope this helped.

Richard Weir  Monday, July 11, 2005 5:32 PM

Hi WinsFormsUser;
I had the same problem.....The only way I have found so far is by setting the OwnerDraw property and programatically setting the properties for the listviewitem... take a look at the OwnerDraw properties documentation.

Hope this helped.

Richard Weir  Monday, July 11, 2005 5:32 PM
Could you (or anyone else ) give an example what exactly you have to code, to make text multiline in a listview?

I went through the OwnerDraw properties documentation, but it wasn't helpful in this context (granted, I now know how to set a different background color and to color text will surely be helpful some time. The hint for the DoubleBuffered setting was good too ).

I guess you have to code this part in the DrawSubItem-Handler?

This is my code for this handler so far:


Private Sub listView1_DrawSubItem(ByVal sender As Object, _
ByVal e As DrawListViewSubItemEventArgs) _
Handles ListView1.DrawSubItem

Dim sf As New StringFormat

Try

sf.Alignment = StringAlignment.Near
sf.Trimming = StringTrimming.EllipsisCharacter

e.Graphics.DrawString(e.SubItem.Text, e.Item.ListView.Font, Brushes.Black, e.Bounds, sf)

Finally
sf.Dispose()
End Try

End Sub


EDIT:
Ok, so I did some more research :) As I see it, there is no way to create ListView-Items or TreeView-Nodes, that are custom sized. All items in a List- or TreeView must have the same size. The only way around this would be to send calls to the Win32 Api to capture the MeasureItem events.
But then I'd like to know why there is no overridable method for MeasureItem, when the ListBox, for example, has it?
strombringer  Tuesday, April 11, 2006 4:34 PM

hi richard can u give me some example how to do that...

new to windows form...

nitsb  Saturday, December 23, 2006 12:28 PM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview row validatinq event & focus
• Funky text / polygon-shaped text
• Icons
• ActiveX within ActiveX
• TreeView Problem
• How to change button appearance?
• Extend control functionality without subclass
• force the hortizontal scroll bar to appear in a DataGrid
• WebBrowser Control - how to disable file downloads?
• Project References - How do I get the DLL Version Numbers