[ http://blog.csdn.net/u010335298/article/details/50956995 ]
2 . 用ListView的addHeaderView方法,为ListView设置一个headView作为下拉刷新的view ,通过设置headView的topPadding来显示和隐藏headView , topPadding = - headHeight的时候,headView隐藏,topPadding = 0 时 ,头部恰好完全出现 。这篇博客就是用这种思路实现的
先说明一点,本事例单击是在listview的每一次第一列出一个下拉列表框,要在其他列出现,可能要用GetCursorPos(pos)来确置了,你自己完善吧,哈哈!unit Unit1
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls
type
TForm1 = class(TForm)
ListView1: TListView
ComboBox1: TComboBox
procedure FormDestroy(Sender: TObject)
procedure ListView1Click(Sender: TObject)
private
FComboBox: TComboBox
{ Private declarations }
procedure CreateCombobox(var aComboBox:TComboboxaLeft, aTop: integer)
procedure MyComboBoxChange(Sender: TObject)
procedure MyComboBoxExit(Sender: TObject)
public
{ Public declarations }
end
var
Form1: TForm1
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.CreateCombobox(var aComboBox: TCombobox
aLeft, aTop: integer)
begin
aComboBox := TComboBox.Create(Self)
aComboBox.Parent := Self
aComboBox.OnChange := MyComboBoxChange
aComboBox.OnExit := MyComboBoxExit
aComboBox.DropDownCount := 5
aComboBox.Style := csDropDown
aComboBox.Items.Add('字段')
aComboBox.Items.Add('aaa')
aComboBox.Items.Add('bbb')
aComboBox.Items.Add('ccc')
aComboBox.Items.Add('其他类型')
aComboBox.Left := aLeft + ListView1.Left + 1
aComboBox.Top := aTop + ListView1.Top + 1
aComboBox.Width := 50
aComboBox.BringToFront
aComboBox.SetFocus
end
procedure TForm1.MyComboBoxChange(Sender: TObject)
begin
if Assigned(ListView1.Selected) then
ListView1.Selected.Caption := TCombobox(Sender).Text
end
procedure TForm1.MyComboBoxExit(Sender: TObject)
begin
try
FComboBox.Free
except
end
FComboBox := nil
end
procedure TForm1.FormDestroy(Sender: TObject)
var
lp: integer
begin
for lp := ComponentCount - 1 downto 0 do
begin
if Components[lp] is TCombobox then
begin
TCombobox(Components[lp]).Free
end
end
FComboBox := nil
end
procedure TForm1.ListView1Click(Sender: TObject)
begin
FormDestroy(Sender)
if Assigned(ListView1.Selected) then
CreateCombobox(FComboBox, ListView1.Selected.Left, ListView1.Selected.Top)
end
end.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)