Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-07
10
Medium Priority
?
212 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 180 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 320 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

721 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