Solved

Modify TListView.Item by popupwindow: How do I know who the parent-Item was?

Posted on 2004-04-07
10
206 Views
Last Modified: 2010-04-05
Hi,

I have a TListView. Now I'd like to modify the subitems by a popup-window.
So I create a form which is invisible at startup (the popup-window). When I press a button or klick a popup-menu, this window gets visible and I can enter my changings.
But how do I know which Item was the parent of the popup-window (which Item I have to modify)?

thanks
0
Comment
Question by:Bohne
  • 6
  • 2
  • 2
10 Comments
 
LVL 17

Assisted Solution

by:mokule
mokule earned 45 total points
ID: 10777364
May be this can help You

var
  ht: THitTests;
  Node: TTreeNode;
begin
  ht := TreeView1.GetHitTestInfoAt(X,Y);
  Node := TreeView1.GetNodeAt(X,Y);
  if ((htOnStateIcon in ht) and(Node <> nil)) then
0
 

Author Comment

by:Bohne
ID: 10777432
I just got an idea myself! ;-) I could try ListView.Selected! If anybody has a better idea, just post...
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 80 total points
ID: 10777557
Heres a solution for right clicking on a TListView Item

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
 ht: THitTests;
 Item: TListItem;
begin
 if button = mbRight then
 begin
  Ht:= ListView1.GetHitTestInfoAt(X,Y);
  Item:= ListView1.GetItemAt(X,Y);
  if Item <> nil then
   if frmPopWindow.ShowModal = mrOK then
    Item.Caption:= frmPopWindow.Edit1.Text;
 end;
end;

Shane
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10777570
Here is a button click example:

procedure TForm1.Button1Click(Sender: TObject);
begin
 if (ListView1.SelCount = 1) AND (ListView1.Selected <> nil) then
 if frmPopWindow.ShowModal = mrOK then
    ListView1.Selected.Caption:= frmPopWindow.Edit1.Text;
end;

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10777609
If you want to modify the subitem create a form with all the edits for the item

i.e. and edit for the caption, and all the subitems

procedure TForm1.Button1Click(Sender: TObject);
begin
 if (ListView1.SelCount = 1) AND (ListView1.Selected <> nil) then
 begin
  frmPopWindow.edit1.Text:=  ListView1.Selected.Caption;
  frmPopWindow.edit2.Text:=  ListView1.Selected.SubItems[0];
  frmPopWindow.edit3.Text:=  ListView1.Selected.SubItems[1];
  frmPopWindow.edit4.Text:=  ListView1.Selected.SubItems[2];
  if frmPopWindow.ShowModal = mrOK then
  begin
   ListView1.Selected.Caption:= frmPopWindow.edit1.Text;
   ListView1.Selected.SubItems[0]:= frmPopWindow.edit2.Text;
   ListView1.Selected.SubItems[1]:= frmPopWindow.edit3.Text;
   ListView1.Selected.SubItems[2]:= frmPopWindow.edit4.Text;
  etc., etc.
  end;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10777623
Here it is again for the Right CLick

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
 ht: THitTests;
 Item: TListItem;
begin
 if button = mbRight then
 begin
  Ht:= ListView1.GetHitTestInfoAt(X,Y);
  Item:= ListView1.GetItemAt(X,Y);
  if Item <> nil then
  begin
   frmPopWindow.edit1.Text:=  ListView1.Selected.Caption;
   frmPopWindow.edit2.Text:=  ListView1.Selected.SubItems[0];
   frmPopWindow.edit3.Text:=  ListView1.Selected.SubItems[1];
   frmPopWindow.edit4.Text:=  ListView1.Selected.SubItems[2];
   if frmPopWindow.ShowModal = mrOK then
   begin
    ListView1.Selected.Caption:= frmPopWindow.edit1.Text;
    ListView1.Selected.SubItems[0]:= frmPopWindow.edit2.Text;
    ListView1.Selected.SubItems[1]:= frmPopWindow.edit3.Text;
    ListView1.Selected.SubItems[2]:= frmPopWindow.edit4.Text;
    etc., etc.
   end;
 end;
end;


Shane
0
 

Author Comment

by:Bohne
ID: 10778806
I wanted to do the right-click thing with a popup-menu and not just with one single click. How can I make sure, that the menu is only shown when clicking on a Item and not in the whole ListView-object?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10778901
Create a popupmenu item, set its caption to 'Edit'

 EditPopupItem.Enabled:= (ListView1.SelCount = 1) AND (listView1.Selected <> nil);

SHane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10778906
ht := ListView1.GetHitTestInfoAt(X,Y);
 
htAbove      Above the client area.
htBelow      Below the client area.
htNowhere      Inside the control, but not on an item.
htOnItem      On an item, its text, or its bitmap.
htOnButton      On a button.
htOnIcon      On an icon.
htOnIndent      On the indented area of an item.
htOnLabel      On a label.
htOnRight      On the right side of an item.
htOnStateIcon      On a state icon or bitmap associated with an item.
htToLeft      To the left of the client area.
htToRight      To the right of the client area.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10778919
Then use the Button's OnCLick event code for the Epopup menu item's on click event

Shane
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ddeman not working in activex 3 103
indy Tmemory stream non latin charcter issue 2 110
Find and Replace Stream with 0s 8 62
Delphi Yen format 3 35
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question