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 Class

Provides data for the ListView::DrawItem event.

System::Object
  System::EventArgs
    System.Windows.Forms::DrawListViewItemEventArgs

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

public ref class DrawListViewItemEventArgs : public EventArgs

The DrawListViewItemEventArgs type exposes the following members.

  NameDescription
Public methodDrawListViewItemEventArgsInitializes a new instance of the DrawListViewItemEventArgs class.
Top

  NameDescription
Public propertyBoundsGets the size and location of the ListViewItem to draw.
Public propertyDrawDefaultGets or sets a property indicating whether the ListView control will use the default drawing for the ListViewItem.
Public propertyGraphicsGets the Graphics used to draw the ListViewItem.
Public propertyItemGets the ListViewItem to draw.
Public propertyItemIndexGets the index of the ListViewItem within the Items collection of the containing ListView.
Public propertyStateGets the current state of the ListViewItem to draw.
Top

  NameDescription
Public methodDrawBackgroundDraws the background of the ListViewItem using its current background color.
Public methodDrawFocusRectangleDraws a focus rectangle for the ListViewItem if it has focus.
Public methodDrawText()Draws the text of the ListViewItem using its current foreground color.
Public methodDrawText(TextFormatFlags)Draws the text of the ListViewItem using its current foreground color and formatting it with the specified TextFormatFlags values.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The ListView::DrawItem event enables you to customize the appearance of a ListView control using owner drawing.

The ListView::DrawItem event is raised by a ListView control when the ListView::OwnerDraw property is set to true. The DrawListViewItemEventArgs passed to the event handler contains information about the ListViewItem to draw and also provides methods to help you draw the item.

Use the State or Item properties to retrieve information about the item to draw. Use the DrawListViewItemEventArgs::ItemIndex property to retrieve the index of the item.

Use the Graphics property to do the actual drawing within the area specified by the Bounds property. To draw standard ListView elements that do not need customization, use the DrawBackground, DrawText, and DrawFocusRectangle methods.

NoteNote

To avoid issues with graphics flickering when owner drawing, override the ListView control and set the DoubleBuffered property to true. This feature is available only on Windows XP and the Windows Server 2003 family when your application calls the Application::EnableVisualStyles method.

The following code example demonstrates how to provide custom drawing for a ListView control. The ListView control in the example has a gradient background. Subitems with negative values have a red foreground and a black background.

A handler for the ListView::DrawItem event draws the background for entire items. A handler for the ListView::DrawSubItem event draws the text values and both the text and background for subitems that have negative values. A handler for the DrawColumnHeader event draws each column header.

A ContextMenu component provides a way to switch between the details view and the list view. In the list view, only the ListView::DrawItem event is fired. In this case, the text and background are both drawn in the ListView::DrawItem event handler.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft