Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView text is truncated -- how do I display the entire text of an item?

Here's a picture of a System.Windows.Forms.ListView using LargeIcons

alt text

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 ?

like image 482
Anonym Avatar asked Nov 29 '10 20:11

Anonym


1 Answers

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.

like image 123
Tomas Voracek Avatar answered Oct 02 '22 21:10

Tomas Voracek