Reputation: 535
Here's a picture of a System.Windows.Forms.ListView using LargeIcons
The selected item shows all it's text
e.g. The top left item shows only 11 characters of its name, it's shown fully if that's selected. How can I make it show all the text(or atleast more than 11 characters), for items that's not selected ?
Upvotes: 7
Views: 4086
Reputation: 5230
Caveat: this worked for me when the View type was Details, I haven't tried LargeIcons.
After writing output (mine was in bulk) to the listview add the following:
lstResults.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize);
lstResults.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
Upvotes: 0
Reputation: 5914
There is DrawItem event http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.drawitem.aspx. Inside this event you have access to System.Drawing.Graphics.DrawString method.
void view_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.Graphics.DrawString(e.Item.Text, drawFont, Brushes.Black,
new RectangleF(e.Item.Position.X,
e.Item.Position.Y,
20,
160));
}
I entered some values for width/height, but you should use MeasureString or similar method. Also do not forget to set OwnerDraw=true on ListView, otherwise it will not work.
Upvotes: 2
Reputation: 2752
I had this problem a while ago and solved by inserting a space after x characters and/or before a capital letter, so the text is wrapped where I wanted it to. This is somewhat a hack but it's an easy fix. You of course need to keep track of the changed you made to the text so you can reverse it if the user selects the item for further use.
Upvotes: 0