Board index » delphi » ListView and PopupMenu

ListView and PopupMenu


2003-07-09 11:43:03 PM
delphi91
Hello All;
I need to add a different PopupMenu to each "SubItem Cell" In the ListView.
I have heard that this can be accomplished. But cannot find no information
on it.
I am using the default "TListView" But if someone else knows of another
ListView
Component that makes this easier, and that is Freeware I'd love to know.
Thank you All
Wayne
 
 

Re:ListView and PopupMenu

Wayne & Carr writes:
Quote
Hello All;

I need to add a different PopupMenu to each "SubItem Cell" In the ListView.
I have heard that this can be accomplished. But cannot find no information
on it.
I am using the default "TListView" But if someone else knows of another
ListView
Component that makes this easier, and that is Freeware I'd love to know.

Thank you All
Wayne


Hello Wayne
I wrote a Exsample a new Component based on TCustomListView
unit ExListView;
interface
uses
Windows, SysUtils, Classes, Controls, ComCtrls, Types, Messages;
type
TNotifyPopup = procedure(Sender : TObject;const Item : TListItem;
SubIndex : Integer;OnHeader : Boolean) of
Object;
TExListView = class(TCustomListView)
private
{ Private-Deklarationen }
FNotifyPopup : TNotifyPopup;
procedure DoBeforePopup(XY : TPoint);
procedure WMContextMenu(var Message: TWMContextMenu); message
WM_CONTEXTMENU;
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
published
{ Published-Deklarationen }
// The new Event to Change Popup at Runtime
property OnBeforePopup : TNotifyPopup read FNotifyPopup write
FNotifyPopup;
property Action;
property Align;
property AllocBy;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Checkboxes;
property Color;
property Columns;
property ColumnClick;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FlatScrollBars;
property FullDrag;
property GridLines;
property HideSelection;
property HotTrack;
property HotTrackStyles;
property HoverTime;
property IconOptions;
property Items;
property LargeImages;
property MultiSelect;
property OwnerData;
property OwnerDraw;
property ReadOnly default False;
property RowSelect;
property ParentBiDiMode;
property ParentColor default False;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowColumnHeaders;
property ShowWorkAreas;
property ShowHint;
property SmallImages;
property SortType;
property StateImages;
property TabOrder;
property TabStop default True;
property ViewStyle;
property Visible;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnAdvancedCustomDrawSubItem;
property OnChange;
property OnChanging;
property OnClick;
property OnColumnClick;
property OnColumnDragged;
property OnColumnRightClick;
property OnCompare;
property OnContextPopup;
property OnCustomDraw;
property OnCustomDrawItem;
property OnCustomDrawSubItem;
property OnData;
property OnDataFind;
property OnDataHint;
property OnDataStateChange;
property OnDblClick;
property OnDeletion;
property OnDrawItem;
property OnEdited;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetImageIndex;
property OnGetSubItemImage;
property OnDragDrop;
property OnDragOver;
property OnInfoTip;
property OnInsert;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnSelectItem;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Exsample', [TExListView]);
end;
procedure TExListView.DoBeforePopup(XY : TPoint);
var
item : TListItem;
R,SR : TRect;
g,width,
height : Integer;
InRect : Boolean;
begin
item := GetItemAt(BevelWidth+2,XY.y); //Get TListItem at Point X/Y
if Assigned(item) then begin //Item at Point ?
R := Item.DisplayRect(drBounds); // Get Rect for Caption
height := R.bottom - R.top; // Calc Height Display height
width := 0;
InRect := false;
for g := 0 to Columns.Count -1 do // Calculate the Rect for each
Item/Subitem
begin
SR := R;
SR.Left := width;
width := width + Columns[g].Width;
SR.Right := width;
if PtInRect(SR,Point(XY.x,XY.y)) or //Item or Header are allowed
(ShowColumnHeaders and PtInRect(SR,Point(XY.x,XY.y + Height)))
then begin
InRect := true;
break;
end;
end;
if Assigned(FNotifyPopup) then // Event is assigned
if InRect then begin // Mouse is in any Item/Subitem Rect
if ShowColumnHeaders and (XY.Y <= Height) then //Headers are
displayed and Mouse on Header
FNotifyPopup(self,Item,g-1,true)
else // not on a Header
FNotifyPopup(self,Item,g-1,false);
end else FNotifyPopup(self,nil,-1,false); //Event not assigned
end else if Assigned(FNotifyPopup) then
FNotifyPopup(self,Item,-1,false); //Mouse not on a Header/Item...
end;
{Override Message for Context Popup}
procedure TExListView.WMContextMenu(var Message: TWMContextMenu);
begin
if ViewStyle = vsReport then
DoBeforePopup(ScreenToClient(SmallPointToPoint(Message.Pos)));
inherited;
end;
Hopes I could assist to you
P.S I can mail also an example to you
Greetings from Hamburg(Germany)
XXXX@XXXXX.COM
 

Re:ListView and PopupMenu

Hello Donat Meyer;
( I Tried to e-mail you , but it was returned back to me.)
You can send me a demo to:
delphi @ carrz-fox-fire.com // broken to stop Spammers
Thank you for the Component, I have not installed it yet, as I
Have just checked the newsgroup and found it.
I would love to have an example of it, that would be great.
And maybe looking at your component will give me some idea's
On some features to it as well.
Thank you
Wayne
 

Re:ListView and PopupMenu

Hello "Donat Meyer";
Great component and Demo.
Very well done.
Take Care
Wayne
 

Re:ListView and PopupMenu

Hello
My Exsample is not a ready to use Component
only a base to work on
D.Meyer