Recent

Author Topic: TListView.onCustomDrawSubItem - How to draw the selected subitem?  (Read 5293 times)

zamtmn

  • Sr. Member
  • ****
  • Posts: 365
TListView.onCustomDrawSubItem - How to draw the selected subitem?
« on: September 01, 2013, 09:08:41 pm »
Hi All!
I'm trying to draw an subitem in the selected state.
Code: [Select]
          if (cdsSelected in state)or(cdsFocused in state) then
          begin
          Sender.canvas.Brush.Color:=clHighlight;
          Sender.canvas.Font.Color:=clHighlightText;
          end;
          aRect:=Item.DisplayRectSubItem( SubItem,drBounds);
          Sender.canvas.FillRect(aRect);
          DefaultDraw:=false;
When I select a row drawn all right, but if move mouse to my selected subitem and stop it for a split second. Ceases to be an element of the selection. Please tell me how.
Example and screen attached

howardpc

  • Hero Member
  • *****
  • Posts: 3176
Re: TListView.onCustomDrawSubItem - How to draw the selected subitem?
« Reply #1 on: September 01, 2013, 11:15:24 pm »
You could try this:
Code: [Select]
begin
  if (subitem=2) and (Item.Focused or Item.Selected) then
  begin
    Sender.Canvas.Brush.Color:=clHighlight;
    Sender.Canvas.Font.Color:=clHighlightText;
    aRect:=Item.DisplayRectSubItem(SubItem, drBounds);
    Sender.Canvas.FillRect(aRect);
    DefaultDraw:=False;
  end;
end; 
Presumably you also want to custom draw some text?
However, drawing outside a Paint procedure is tricky.

zamtmn

  • Sr. Member
  • ****
  • Posts: 365
Re: TListView.onCustomDrawSubItem - How to draw the selected subitem?
« Reply #2 on: September 02, 2013, 08:27:22 am »
No, it is also wrong. result in attachment. As far as I understand, this is a bug. In Delphi cares about the background color inappropriately, it is set within VCL.