Solved

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

Posted on 2004-04-07
10
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi : could not find program, '...exe' 2 214
Making delphi communicate with a c# service 16 122
When i run adoquery my application freezes 26 190
Browsing a TTreeView in Delphi 5 32
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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