5,386
社区成员
发帖
与我相关
我的任务
分享
implementation
{$R *.dfm}
const
aCheck = '√';
uCheck = '×';
var
EdtCol: Integer; // 记录EDIT1在Columns中的位置,1- MaxColumns;
EdtItem: Tlistitem;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListView1.ViewStyle := vsReport;
ListView1.RowSelect := True;//必须
end;
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
R: Trect;
Pt: TPoint;
wtmp, i: Integer;
begin
try
EdtItem := ListView1.GetItemAt(X, Y); // 根据鼠标位置,得到所对应行的LISTITEM
if EdtItem <> nil then
begin
// 根据鼠标位置,计算出是哪个 Columns.
Pt := EdtItem.Position;
wtmp := Pt.X;
for i := 0 to ListView1.Columns.Count - 1 do
if (X > wtmp) and (X < (wtmp + ListView1.Column[i].Width)) then
Break // 找到对应的Columns.
else
inc(wtmp, ListView1.Column[i].Width);
// 根据I的值,取得 Columns的对应位置。
EdtCol := i;
R := EdtItem.DisplayRect(drSelectBounds);
if (EdtCol > 0) and (i < 6) then
begin
if EdtItem.SubItems[i - 1] = aCheck then
EdtItem.SubItems[i - 1] := uCheck
else
EdtItem.SubItems[i - 1] := aCheck;
end
end;
except
//
end;
end;