How to draw an underline on a Listview Caption (Views: 52)


Can you underline the caption of a ListView Item?


To draw an Underline on a Listview Caption the same like the HotTrack function in Delphi 6 in Delphi 3 you must call an API function.

In the Uses Clausse inpelement the CommCtrl unit.

Then you set the following code in the MouseMove property of your ListView.

procedure TfrmMain.lvwMainMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
  LVS_EX_UNDERLINEHOT = $00000800;
  LVS_EX_INFOTIP = $00000400;
  AItem: TListItem;
  Styles: DWord;
  //This line is a VCL Bugfix for the ListView
  Styles := LVS_EX_INFOTIP;
  AItem := lvwMain.GetItemAt(X, Y);
  if not Assigned(AItem) then
    lvwMain.Cursor := crArrow;
    lvwMain.Cursor := crHandPoint;
    Styles := Trunc(Styles + LVS_EX_UNDERLINEHOT - LVS_EX_CHECKBOXES -
    ListView_SetExtendedListViewStyle(lvwMain.Handle, Styles);

When you goes with your mouse over an ListView Item there will be an underline drawed under the caption of the Item.

Because the value that exists in the Styles variabele allso enables checkboxes and rowselect add the following lines under the Styles lines and above the SetExtendedListViewStyle.

Styles := Styles - LVS_EX_CHECKBOXES;
Styles := Styles - LVS_EX_TRACKSELECT;

This will fix the bug of the Checkboxes and TrackSelecting.

<< Back to main page