Still problems wit TListview when I want some different.
It;s a great component if you change nothing like colors and selection.
WP told me to het property hideselection to false. The selectbar will not dissapear. He's correct, but the Tlistview displays the selectbar as grey when there's no focus.
To make it permanent you have to use OnCustomDrawItem and OnCustomDrawSubItem. So I made a small demo with a listview on form and set it to vsReport. By creating a form, I fill the columns with data. So far so good.
Now I set property ownerdraw to true. Now I need OncustomDrawItem to get some text in TListview:
r := Item.DisplayRect(drBounds);
listview1.Canvas.TextRect(r,r.Left + 5,r.Top + 1,'hallo');
defaultdraw := false;
This works only for items, not subitems. It'als repainting the text when you place the mouse cursor on a item.
The rest of the subitems must be filed by OnCustomDrawSubItem :
r := Item.DisplayRectSubItem(subitem,drBounds);
listview1.Canvas.TextRect(r,r.Left + 5,r.Top + 1,'subhallo');
defaultdraw := false;
But TListview shows nothing on screen on subitems. Even when I put a debu stop on the procedure it wil not stop.
My conclusion OnCustomDrawItem is filled with code, OnCustomDrawSubItem is not working.
If I delete OnCustomDrawItem the default items are showed into TListview and subitems are only on screen when I move the mouse cursor.
Very strange behaviour. There's is something not working correctly.
I only wat to have odd lines to color and a permanent selectbar with the same color when active / inactive
When I use this code in OnCustomDrawItem and TListview is inactive the whole listview will ne colored:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var r : TRect;
begin
if (cdsSelected in state) or (cdsGrayed in state) then
begin
listview1.Canvas.Brush.Color := clRed;
r := Item.DisplayRect(drBounds);
listview1.canvas.FillRect(r);
listview1.Canvas.TextRect(r,r.Left + 5,r.Top + 1,'hallo');
defaultdraw := false;
end;
end;
another problem is aligning. I have listview with some numbers which are aligned to RightJustify.
I have a piece of code that runs only in OnDrawItem, but when a line is selected, all text aligned to right are put on left.