请问如何在listview中的一列单元格中添加combox(100分)

  • 主题发起人 主题发起人 agu9899
  • 开始时间 开始时间
A

agu9899

Unregistered / Unconfirmed
GUEST, unregistred user!
如题!我想双击listview一列中的某个单元格,就有个下拉框供用户选择,请大家赐教,立刻给分
 
用一个combobox控件移动过去
 
http://www.nssoft.net/showdoc.asp?did=317
希望对你有点启发,我没做过,成不成靠你了.
 
希望大家帮忙,或者推荐具备我所说功能的组件
 
请高手帮忙!!!
 
麻烦你帮我看下这个问题
 
如果只有2列,就有一个
 
unit uMain;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,Commctrl;

type
TForm1 = class(TForm)
ListView1: TListView;
cb_View: TComboBox;
Memo1: TMemo;
procedure ListView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ListView1DblClick(Sender: TObject);
procedure cb_ViewExit(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FCurItem:integer;
FCurSub:integer;
FX,FY:integer;
public
{ Public declarations }
procedure AddMyItem(cmd,Content:string);
end;

var
Form1: TForm1;

implementation

{$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;

end.
 
上一个哥们的启发:弹出一个窗体:
窗体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.
 
[:D]我也没有写过。应该在下面的事件里自己画combobox吧
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin

end;

procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin

end;
 
多人接受答案了。
 
后退
顶部