PDA

Ver la Versión Completa : Listview color fondo


ANALBA
27-08-2008, 10:10:03
Tengo un listview que cargo manualmente y en el evento CustomDrawSubItem pongo el siguiente codigo:


if (Item.Selected) then
Begin
Sender.Canvas.Brush.Color := clblue;
end;


He probado poner esto tambien:


if (Item.Selected) then
Begin
SetBkColor(Sender.Canvas.Handle, clblue);
end;


Obteniendo el mismo resultado, en los dos casos pone el fondo azul en el texto de cada subitem, pero no pone toda la linea azul, como cuando seleccionas una en automatico, alguien sabe que me falta o que estoy haciendo mal.

Gracias y un saludo

duilioisola
27-08-2008, 11:18:48
Creo que debería ser así:


if (Item.Selected) then
Begin
Item.Canvas.Brush.Color := clblue;
end;


Según el Help de Delphi:

TCustomListView.OnCustomDrawSubItem
Occurs when a subitem must be rendered in an owner-draw list view.

type TLVCustomDrawSubItemEvent = procedure(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean) of object;
property OnCustomDrawSubItem: TLVCustomDrawSubItemEvent

Description

Write code in an OnCustomDrawSubItem handler to draw to the subitems that appear in additional columns to the right of each item when ViewStyle is vsReport. Use the list view’s Canvas property as a drawing surface. Unlike the OnDrawItem event, the list view receives this event even if the OwnerDraw property is False.

The Sender Parameter specifies the list view that owns the subitems. The Item parameter is the current Item being drawn. The SubItem parameter is the index of the subitem of that list item in its SubItems property. The State property indicates various attributes that can affect the way the subitem is drawn. Set DefaultDraw to False to prevent the list view from adding the subitem’s text after the event handler exits.

Note: OnCustomDrawSubItem occurs immediately prior to the rendering of each subitem. To augment the default drawing process at other stages (such as after the subitem is drawn), use the OnAdvancedCustomDrawSubItem event instead.

ANALBA
27-08-2008, 11:23:38
Gracias por tu respuesta pero lo he probado tal cual me dices y el Item no tiene la propiedad Canvas lo has puesto tu de alguna otra manera.

Un saludo

duilioisola
27-08-2008, 11:48:12
No, lo puse rápidamente, sin comporbarlo.

Mirando el Help de Delphi sobre TListItem encontré esta propiedad que supongo te puede servir:

TListItem.DisplayRect
Returns the bounding rectangle of the list item.

type TDisplayCode = (drBounds, drIcon, drLabel, drSelectBounds);
function DisplayRect(Code: TDisplayCode): TRect;

Description

Use DisplayRect to get the coordinates of the list item in the client coordinates of the containing listview. The Code parameter specifies what part of the item the bounding rectangle surrounds. These are the possible values for the Code parameter.

Value Meaning

drBounds Returns the bounding rectangle of the entire list item, including the icon and label.
drIcon Returns the bounding rectangle of the icon or small icon
drLabel Returns the bounding rectangle of the item text
drSelectBounds Returns the union of the icon and label rectangles, but excludes columns in report view

Podrías escribir un rectánculo de color sobre el canvas de "Sender"