日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

ListView用法[delphi

 遠(yuǎn)在南非 2010-07-09
ListView用法[delphi]
2010-06-24 22:56

//增加
i := ListView1.Items.Count;
with ListView1 do
begin
ListItem:=Items.Add;
ListItem.Caption:= IntToStr(i);
ListItem.SubItems.Add('第 '+IntToStr(i)+' 行');
ListItem.SubItems.Add('第三列內(nèi)容');
end;      //注:必須用with

//按標(biāo)題刪除
for i:=ListView1.Items.Count-1 downto 0 Do
if ListView1.Items[i].Caption = Edit1.Text then
begin
ListView1.Items.Item[i].Delete(); //刪除當(dāng)前選中行
end;

//選中一行
if ListView1.Selected <> nil then
Edit1.Text := ListView1.Selected.Caption;


// listview1.Items[Listview1.Items.Count -1].Selected := True;
// listview1.Items[Listview1.Items.Count -1].MakeVisible(True);
procedure TForm1.Button2Click(Sender: TObject); // 選擇第一條
begin
listview1.SetFocus;
listview1.Items[0].Selected := True;
end;

procedure TForm1.Button1Click(Sender: TObject); // 選擇最后一條
begin
listview1.SetFocus;
listview1.Items[Listview1.Items.Count -1].Selected := True;
end;

//這是個(gè)通用的過(guò)程
procedure ListViewItemMoveUpDown(lv : TListView; Item : TListItem; MoveUp, SetFocus : Boolean);
var
DestItem : TListItem;
begin
if (Item = nil) or
((Item.Index - 1 < 0) and MoveUp) or
((Item.Index + 1 >= lv.Items.Count) and (not MoveUp))
then Exit;
lv.Items.BeginUpdate;
try
if MoveUp then
DestItem := lv.Items.Insert(Item.Index - 1)
else
DestItem := lv.Items.Insert(Item.Index + 2);
DestItem.Assign(Item);
lv.Selected := DestItem;
Item.Free;
finally
lv.Items.EndUpdate;
end;
if SetFocus then lv.SetFocus;
DestItem.MakeVisible(False);
end;

//此為調(diào)用過(guò)程,可以任意指定要移動(dòng)的Item,下面是當(dāng)前(Selected)Item
ListViewItemMoveUpDown(ListView1, ListView1.Selected, True, True);//上移
ListViewItemMoveUpDown(ListView1, ListView1.Selected, False, True);//下移


TListView組件使用方法

引用CommCtrl單元

procedure TForm1.Button1Click(Sender: TObject);
begin
ListView_DeleteColumn(MyListView.Handle, i);//i是要?jiǎng)h除的列的序號(hào),從0開(kāi)始

end;

用LISTVIEW顯示表中的信息:
procedure viewchange(listv:tlistview;table:tcustomadodataset;var i:integer);
begin
tlistview(listv).Items.BeginUpdate; {listv:listview名}
try
tlistview(listv).Items.Clear;
with table do {table or query名}
begin
active:=true;
first;
while not eof do
begin
listitem:=tlistview(listv).Items.add;
listitem.Caption:=trim(table.fields[i].asstring);
// listitem.ImageIndex:=8;
next;
end;
end;
finally
tlistview(listv).Items.EndUpdate;
end;
end;



ListView使用中的一些要點(diǎn)。以下以一個(gè)兩列的ListView為例。
→增加一行:
with ListView1 do
begin
ListItem:=Items.Add;
ListItem.Caption:='第一列內(nèi)容';
ListItem.SubItems.Add('第二列內(nèi)容');
end;
→清空ListView1:
ListView1.Items.Clear;
→得到當(dāng)前被選中行的行的行號(hào)以及刪除當(dāng)前行:
For i:=0 to ListView1.Items.Count-1 Do
If ListView1.Items[i].Selected then //i=ListView1.Selected.index
begin
ListView1.Items.Delete(i); //刪除當(dāng)前選中行
end;
當(dāng)然,ListView有OnSelectItem事件,可以判斷選擇了哪行,用個(gè)全局變量把它賦值出來(lái)。
→讀某行某列的操作:
Edit1.Text := listview1.Items[i].Caption; //讀第i行第1列
Edit2.Text := listview1.Items[i].SubItems.strings[0]; //讀第i行第2列
Edit3.Text := listview1.Items[i].SubItems.strings[1]; //讀第i行第3列
以次類(lèi)推,可以用循環(huán)讀出整列。
→將焦點(diǎn)上移一行:
For i:=0 to ListView1.Items.Count-1 Do
If (ListView1.Items[i].Selected) and (i>0) then
begin
ListView1.SetFocus;
ListView1.Items.Item[i-1].Selected := True;
end;
不過(guò)在Delphi6中,ListView多了一個(gè)ItemIndex屬性,所以只要
ListView1.SetFocus;
ListView1.ItemIndex:=3;
就能設(shè)定焦點(diǎn)了。


Delphi的listview能實(shí)現(xiàn)交替顏色么?
procedure TForm1.ListView1CustomDrawItem(
Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
i: integer;
begin
i:= (Sender as TListView).Items.IndexOf(Item);
if odd(i) then sender.Canvas.Brush.Color:= $02E0F0D7
else sender.Canvas.Brush.Color:= $02F0EED7;
Sender.Canvas.FillRect(Item.DisplayRect(drIcon));
end;

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多