Доброе время суток.
демка
http://kolmck.net/demos/DemoListViewChkBoxes.zipвопрос в следующем: почему не отображает chkbox'сы?
код:
program lvchkboxs;
uses
windows,
kol;
type TOnEvent = procedure( Sender: PObj )of object;
var
form,LV,P,Btn:PControl;
ImageList:PImageList;
Timer:pTimer;
i:Integer;
const range=10;
procedure clickbutton1(Dummy:Pointer;Sender:PControl; var mouse:TMouseEventData);
begin
if Timer.Enabled then
begin
Timer.Enabled:=False;
Btn.Caption:='Demonstrate';
end
else
begin
Timer.Enabled:=True;
Btn.Caption:='Stop';
LV.Focused:=True;
end;
end;
procedure CheckIcon(LV: PControl; Item: Integer);
begin
if LV.LVItemImageIndex[Item]<>1 then
LV.LVItemImageIndex[Item]:=1
else
LV.LVItemImageIndex[Item]:=0;
end;
procedure LVMouseDown(Dummy:Pointer;Sender: PControl;var Mouse: TMouseEventData);
type
TLVHitTestInfo = packed record
pt: TPoint;
flags: DWORD;
iItem: Integer;
iSubItem: Integer;
end;
var
HTI: TLVHittestinfo;
begin
HTI.pt.x:=Mouse.X;
HTI.pt.y:=Mouse.y;
LV.Perform(LVM_HITTEST, 0, Integer(@ HTI));
if LongBool(HTI.flags and LVHT_ONITEMICON) then
CheckIcon(LV, HTI.iItem);
end;
procedure LVKeyDown(Dummy:Pointer;Sender: PControl; var Key: Integer;
Shift: Cardinal);
begin
if Key=VK_SPACE then
if LV.CurIndex>=0 then
CheckIcon(LV, LV.CurIndex);
end;
procedure TimerT(Sender: PObj);
var
r, m: Integer;
begin
r:=random(range+1);
m:=random(range+1);
if (r>LV.Count) or (m>LV.Count) then Exit;
if LV.LVItemImageIndex[r]=0 then
LV.LVItemImageIndex[r]:=1
else
LV.LVItemImageIndex[r]:=0;
LV.LVSetItem(m, 0, LV.LVItems[m, 0], 0 , [lvisSelect], 0, 0, LV.LVItemData[m]);
end;
Begin
form:=NewForm(Applet,'Form1').SetPosition( 507, 362 ).SetSize( 268, 270 );
form.Style := form.Style and not WS_MAXIMIZEBOX;
form.CanResize := false;
ImageList := NewImageList(form );
ImageList.Colors := ilcColor4;
ImageList.ImgWidth := 15;
ImageList.ImgHeight := 15;
ImageList.AddMasked( LoadBitmap( hInstance, 'F_ImgList' ), clMaroon );
LV := NewListView( form, lvsDetail, [ lvoGridLines, lvoRowSelect ], ImageList, nil, nil ).SetPosition( 8, 8 ).SetSize( 241, 210 );
LV.Color := clWindow;
Timer := NewTimer( 100 );
P := NewPanel( form, esLowered ).SetPosition( 8, 216 ).SetSize( 241, 24 );
Btn := NewButton( P, 'Demonstrate' ).SetPosition( 1, 0 ).SetSize( 238, 0 );
LV.LVColAdd('Colum1', taLeft, (LV.Width - 4));
for i:=0 to range do
LV.LVItemAdd('Item: '+Int2Str(i));
Btn.OnClick:=TonEvent(MakeMethod(nil,@clickbutton1));
lv.OnMouseDown:=TonMouse(MakeMethod(nil,@LVMouseDown));
lv.OnKeyDown:=TOnKey(MakeMethod(nil,@LVKeyDown));
Timer.OnTimer:=TonEvent(MakeMethod(nil,@TimerT));
Run(form);
end.