在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
代码
//增加
i := listview1.Items.Count; with ListView1 do begin ListItem:=Items.Add; ListItem.Caption:= IntToStr(i); ListItem.SubItems.Add('第 '+IntToStr(i)+' 行'); ListItem.SubItems.Add('第三列内容'); end; //按标题删除 for i:=ListView1.Items.Count-1 downto 0 Do if ListView1.Items[i].Caption = Edit1.Text then begin ListView1.Items.Item[i].Delete(); //删除当前选中行 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; //此为调用过程,可以任意指定要移动的Item,下面是当前(Selected)Item 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; ListViewItemMoveUpDown(ListView1, ListView1.Selected, True, True);//上移 ListViewItemMoveUpDown(ListView1, ListView1.Selected, False, True);//下移
TListView组件使用方法
代码
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;
读某行某列的操作:
For i:=0 to ListView1.Items.Count-1 Do
不过在Delphi7中,ListView多了一个ItemIndex属性,所以只要
ListView1.SetFocus; ListView1.ItemIndex:=3; 就能设定焦点了。 Delphi的listview能实现交替颜色么?
代码
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; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论