Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DrawListViewItemEventArgs.Item Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the ListViewItem to draw.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public ListViewItem Item { get; }

Property Value

Type: System.Windows.Forms.ListViewItem

The ListViewItem to draw.

Use this property to access the ListViewItem to draw. This is useful when the State property does not provide adequate information to meet your needs. The State property provides only basic state information that you can use, for example, to determine whether an item is selected, checked, or focused. The Item property, on the other hand, allows you to access all members of the ListViewItem. You must access the item directly, for example, to draw the ListViewItem.Text value yourself rather than using the DrawText method.

The following code example demonstrates how to use the Item property in an application that provides custom drawing for a ListView control. In the example, a handler for the ListView.DrawItem event draws the background for entire items. In all views except the details view, this handler also draws the foreground text. In the details view, the foreground text is drawn in the ListView.DrawSubItem event.

For the complete example, see the DrawListViewItemEventArgs overview reference topic.

// Draws the backgrounds for entire ListView items.
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();
    }
}

.NET Framework
Available since 2.0
Return to top
Show:
© 2017 Microsoft