views:

300

answers:

3

Is it possible to draw some strings onto a listview?

I overridden the OnPaint event but I don't see any change. I checked out some code on custom listview, but it seems like people are using p/invoke, etc. Why?

Isn't list as customizable as other winforms, like the Button control?

I am not gonna customize wildly, just paint some more after it's done the standard painting.

+3  A: 
 class MyCustomlistView : ListView
    {
        public MyCustomlistView()
            : base()
        {
            SetStyle(ControlStyles.UserPaint, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.DrawString("This is a custom string", new Font(FontFamily.GenericSerif, 10, FontStyle.Bold), Brushes.Black, new PointF(0, 50));
        }

    }
Ciwee
Thanks, this did the trick.
Joan Venge
This does not work with a ListView. It simply makes the ListView draw nothing.
Grammarian
+1  A: 

Set the OwnerDraw property to true.

You can then handle the DrawItem, DrawSubItem, and DrawColumnHeader events to draw on specific elements of the ListView.

SLaks
+3  A: 
Grammarian