• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

Highlighting TListView Item in OnDragOver

Is it possible to make a Listview item highlighted during the OnDragOver?

I know I can make the entire Listview CustomDrawn and highlight based on certain criteria but how would I change the font color/style, etc. in the dragover?
0
Eddie Shipman
Asked:
Eddie Shipman
  • 3
  • 2
1 Solution
 
Geert GruwezOracle dbaCommented:
using Mike Lischke's VirtualStringTree is not an option ?
it has a property in the treeoptions: ShowDropMark
which highlist the place being dragged over
0
 
Eddie ShipmanAll-around developerAuthor Commented:
nope
0
 
Geert GruwezOracle dbaCommented:
it works for the first column, but i am assuming you want it for the subitems ?
0
 
Geert GruwezOracle dbaCommented:
it don't completely work yet,
it selects all the subitems right of the highlighted one too ...

procedure TForm1.UnSelect;
var I: Integer;
begin
  if Assigned(fPrevItem) then
  begin
    for I := 0 to fPrevItem.SubItems.Count-1 do
      fPrevItem.SubItems.Objects[I] := TObject(2);
    fPrevItem.Update;
  end;
end;
 
procedure TForm1.Select(aItem: TListItem; aIndex: Integer);
begin
  fPrevItem := aItem;
  fPrevIndex := aIndex;
  if fPrevItem <> nil then
  begin
    if fPrevIndex <> -1 then
    begin
      with fPrevItem.SubItems do
          while Count < fPrevIndex+1 do
            AddObject('', nil);
      fPrevItem.SubItems.Objects[fPrevIndex] := TObject(1);
    end;
    fPrevItem.Update;
  end;
end;
 
procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var
  i, xx, w, j: integer;
  item: TListItem;
  lv: TListView;
begin
  Accept := Source = Edit1;
  lv := TListView(Sender);
  item := lv.GetItemAt(10, Y);
  j := -1;
  if Assigned(item) then
  begin
    xx := 0;
    for i := 0 to lv.Columns.Count-1 do
    begin
      w := lv.Columns[I].Width;
      if (x >= xx) and (x < xx + w) then
      begin
        j := i;
        break;
      end else
        xx := xx + w;
    end;
  end;
  UnSelect;
  if (Item <> nil) and (j > 0) then
     Select(Item, j);
end;
 
constructor TForm1.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fPrevItem := nil;
  fPrevIndex := -1;
end;
 
procedure TForm1.ListView1AdvancedCustomDrawSubItem(
  Sender: TCustomListView; Item: TListItem; SubItem: Integer;
  State: TCustomDrawState; Stage: TCustomDrawStage;
  var DefaultDraw: Boolean);
begin
  DefaultDraw := True;
  Sender.Canvas.Brush.Color := clWindow;
  Sender.Canvas.Font.Color := clWindowText;
  if Assigned(Item) then
  begin
    if (Item.SubItems.Count > SubItem) and (SubItem >= 0) and
      (Item.SubItems.Objects[SubItem] = TObject(1)) then
    begin
      Sender.Canvas.Brush.Color := clHighlight;
      Sender.Canvas.Font.Color := clHighlightText;
    end;
  end;
end;

Open in new window

0
 
Eddie ShipmanAll-around developerAuthor Commented:
Well, the Listview descendant that I'm using does not inherently highlight the first column AND the code
above does not work on this control.

I will contact the control author to figure this one out.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now