Solved

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

Posted on 2004-04-07
10
204 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Then use the Button's OnCLick event code for the Epopup menu item's on click event

Shane
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now