Bohne
asked on
Modify TListView.Item by popupwindow: How do I know who the parent-Item was?
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
procedure TForm1.Button1Click(Sender
begin
if (ListView1.SelCount = 1) AND (ListView1.Selected <> nil) then
if frmPopWindow.ShowModal = mrOK then
ListView1.Selected.Caption
end;
Shane
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.SubItem s[0];
frmPopWindow.edit3.Text:= ListView1.Selected.SubItem s[1];
frmPopWindow.edit4.Text:= ListView1.Selected.SubItem s[2];
if frmPopWindow.ShowModal = mrOK then
begin
ListView1.Selected.Caption := frmPopWindow.edit1.Text;
ListView1.Selected.SubItem s[0]:= frmPopWindow.edit2.Text;
ListView1.Selected.SubItem s[1]:= frmPopWindow.edit3.Text;
ListView1.Selected.SubItem s[2]:= frmPopWindow.edit4.Text;
etc., etc.
end;
end;
i.e. and edit for the caption, and all the subitems
procedure TForm1.Button1Click(Sender
begin
if (ListView1.SelCount = 1) AND (ListView1.Selected <> nil) then
begin
frmPopWindow.edit1.Text:= ListView1.Selected.Caption
frmPopWindow.edit2.Text:= ListView1.Selected.SubItem
frmPopWindow.edit3.Text:= ListView1.Selected.SubItem
frmPopWindow.edit4.Text:= ListView1.Selected.SubItem
if frmPopWindow.ShowModal = mrOK then
begin
ListView1.Selected.Caption
ListView1.Selected.SubItem
ListView1.Selected.SubItem
ListView1.Selected.SubItem
etc., etc.
end;
end;
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.SubItem s[0];
frmPopWindow.edit3.Text:= ListView1.Selected.SubItem s[1];
frmPopWindow.edit4.Text:= ListView1.Selected.SubItem s[2];
if frmPopWindow.ShowModal = mrOK then
begin
ListView1.Selected.Caption := frmPopWindow.edit1.Text;
ListView1.Selected.SubItem s[0]:= frmPopWindow.edit2.Text;
ListView1.Selected.SubItem s[1]:= frmPopWindow.edit3.Text;
ListView1.Selected.SubItem s[2]:= frmPopWindow.edit4.Text;
etc., etc.
end;
end;
end;
Shane
procedure TForm1.ListView1MouseDown(
Shift: TShiftState; X, Y: Integer);
var
ht: THitTests;
Item: TListItem;
begin
if button = mbRight then
begin
Ht:= ListView1.GetHitTestInfoAt
Item:= ListView1.GetItemAt(X,Y);
if Item <> nil then
begin
frmPopWindow.edit1.Text:= ListView1.Selected.Caption
frmPopWindow.edit2.Text:= ListView1.Selected.SubItem
frmPopWindow.edit3.Text:= ListView1.Selected.SubItem
frmPopWindow.edit4.Text:= ListView1.Selected.SubItem
if frmPopWindow.ShowModal = mrOK then
begin
ListView1.Selected.Caption
ListView1.Selected.SubItem
ListView1.Selected.SubItem
ListView1.Selected.SubItem
etc., etc.
end;
end;
end;
Shane
ASKER
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?
Create a popupmenu item, set its caption to 'Edit'
EditPopupItem.Enabled:= (ListView1.SelCount = 1) AND (listView1.Selected <> nil);
SHane
EditPopupItem.Enabled:= (ListView1.SelCount = 1) AND (listView1.Selected <> nil);
SHane
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.
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.
Then use the Button's OnCLick event code for the Epopup menu item's on click event
Shane
Shane
ASKER