Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ListView selected item
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01377334
Message ID:
01377357
Views:
18
Neil,
Cool thanks for the code. I had a feeling I had to draw it myself if I wanted something different from M$ behaviour.

>Hi Einar,
>
>You will have to owner draw your listview items. You will need to set the OwnerDraw property on the listview and then hookup to the DrawItem event:-
>
>http://msdn.microsoft.com/en-us/library/system.windows.forms.drawlistviewitemeventargs(VS.80).aspx
>
>The bit you are interested in is the state of the row which you can use the ListViewItemStates enumeration to determine.
>
>private void listView1_DrawItem(object sender,
>    DrawListViewItemEventArgs e)
>{
>    if ((e.State & ListViewItemStates.Selected) != 0)
>    {
>        // Draw the background and focus rectangle for a selected item.
>        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
>        e.DrawFocusRectangle();
>    }
>    else
>    {
>        // Draw the background for an unselected item.
>        using (LinearGradientBrush brush =
>            new LinearGradientBrush(e.Bounds, Color.Orange,
>            Color.Maroon, LinearGradientMode.Horizontal))
>        {
>            e.Graphics.FillRectangle(brush, e.Bounds);
>        }
>    }
>
>    // Draw the item text for views other than the Details view.
>    if (listView1.View != View.Details)
>    {
>        e.DrawText();
>    }
>}
>
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform