Solved

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

Posted on 2004-04-07
10
205 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

21 Experts available now in Live!

Get 1:1 Help Now