上一个哥们的启发:弹出一个窗体:
窗体1代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Commctrl, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
Memo1: TMemo;
cb_view: TComboBox;
procedure ListView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ListView1DblClick(Sender: TObject);
procedure cb_viewExit(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListView1Click(Sender: TObject);
private
{ Private declarations }
FCurItem:integer;
FCurSub:integer;
FX,FY:integer;
public
{ Public declarations }
procedure AddMyItem(cmd, Content: string);
end;
var
Form1: TForm1;
P_lb : integer;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.AddMyItem(cmd, Content: string);
var
LItem:TListItem;
begin
LItem:=ListView1.Items.Add;
with LItem do
begin
Caption:=DateTimeToStr(now);
SubItems.Add(Cmd);
end;
end;
procedure TForm1.ListView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ht: PLVHitTestInfo;
begin
New(ht);
ht.pt.x := X;
ht.pt.Y := Y;
ListView_SubItemHitTest(ListView1.Handle, ht);
Memo1.Lines.Add('iTEM='+IntToStr(ht.iItem)+' Sub'+IntToStr(ht.iSubItem));
if (ht.iSubItem>=0)and(ht.iItem>=0) and (ht.iItem<ListView1.Items.Count-1)
and (ht.pt.X>0) and (ht.pt.Y>0) and (ht.iSubItem<ListView1.Columns.Count) then
try
if ht.pt.X<ListView1.Columns[0].Width then
fx:=2
else
fx:=ListView1.Columns[0].Width+2;
cb_View.SetBounds(fx,ht.pt.Y,ListView1.Columns[ht.iSubItem].Width,10);
//È¡µÃÖµ
FCurItem:=ht.iItem;
FCurSub:=ht.iSubItem;
if FCurSub=0 then
cb_View.Text:=ListView1.Items[fCurItem].Caption
else
cb_View.Text:=ListView1.Items[fcuritem].SubItems[fcursub-1];
except
Memo1.Lines.Add('iTEM='+IntToStr(ht.iItem)+' Sub'+IntToStr(ht.iSubItem));
end;
// ShowMessage(IntToStr(ht.iItem)); //ÐкÅ
// ShowMessage(IntToStr(ht.iSubItem)); //ÁкÅ
end;
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
cb_View.Left:=FY;
cb_View.Top:=FY;
cb_View.Visible:=True;
end;
procedure TForm1.cb_viewExit(Sender: TObject);
begin
if FCurSub=0 then
ListView1.Items[3].Caption:=cb_View.Text
else
ListView1.Items[fcuritem].SubItems[fcursub-1]:=cb_View.Text;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
ListView1.Items.Clear;
for i:=0 to 10 do
AddMyItem('cmd'+IntToStr(i),'Ò»¸ö²Ù×÷£¡');
end;
procedure TForm1.ListView1Click(Sender: TObject);
begin
try
if listview1.Selcount > 0 then
//Application.MessageBox(PChar(listview1.Items[listview1.Selected.index].SubItems.Text), 'Éú³ÉÓÃÀýÈÕÖ¾', MB_Ok);
//¶¨Òåp_lbΪȫ¾Ö±äÁ¿
P_lb := listview1.Selected.index;
form2.ShowModal;
except
end;
end;
end.
窗体2代码:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
f2_cb: TComboBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
unit1.P_lb:=unit1.P_lb; //listviewbox pos
unit1.T_lb:=f2_cb.Text; // ÄÚÈÝ
f2_cb.Text:='';
//»Øдµ½listviewÖС£
with unit1.Form1 do
begin
ListView1.ItemIndex:=unit1.P_lb;
listview1.Items.Item[unit1.P_lb].Caption:=unit1.T_lb;
end;
form2.Close;
end;
end.