//增加项或列(字段)

ListView1.Clear;
ListView1.Columns.Clear;
ListView1.Columns.Add;
ListView1.Columns.Add;
ListView1.Columns.Add;
ListView1.Columns.Items[].Caption:='id';
ListView1.Columns.Items[].Caption:='type';
ListView1.Columns.Items[].Caption:='title';
ListView1.Columns.Items[].Width:=;
Listview1.ViewStyle:=vsreport;
Listview1.GridLines:=true; //注:此处代码也可以直接在可视化编辑器中完成, 也可写成以下这样 begin
with listview1 do
begin
Columns.Add;
Columns.Add;
Columns.Add;
ViewStyle:=vsreport;
GridLines:=true;
columns.items[].caption:='进程名';
columns.items[].caption:='进程ID';
columns.items[].caption:='进程文件路径';
Columns.Items[].Width:=;
Columns.Items[].Width:=;
Columns.Items[].Width:=;
end
end; //增加记录
with listview1.items.add do
begin
caption:='';
subitems.add('hh1');
subitems.add('hh2');
end; //删除
listview1.items.delete(); //从数据库表里读取数据写入Listview var
Titem:Tlistitem; //此处一定要预定义临时记录存储变量.
begin
ListView1.Items.Clear;
with adoquery1 do
begin
close;
sql.Clear;
sql.Add('select spmc,jg,sl from kcxs');
Open;
ListView1.Items.Clear;
while not eof do
begin
Titem:=ListView1.Items.add;
Titem.Caption:=FieldByName('spmc').Value;
Titem.SubItems.Add(FieldByName('sl').Value);
Titem.SubItems.Add(FieldByName('jg').Value);
next;
end; //删除
ListView1.DeleteSelected; //如何取得ListView中选中行的某一列的值 procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(ListView1.Selected.SubItems.Strings[]); //返回选中行第三列中的值
end; showMessage(listView1.Selected.Caption); //返回选中行第一列的值. 第1列的值: -->>> ListView1.Selected.Caption
第i列的值(i>):-->>> ListView1.Selected.SubItems.Strings[i] ListView1.Items.Item[].SubItems.GetText); //取得listview某行某列的值 Edit2.Text := listview1.Items[i].SubItems.strings[]; //读第i行第2列 返回选中行所有子列值.是以回车符分开的,你还要从中剥离出来你要的子列的值。 showMessage(ListView1.Selected.SubItems.GetText); ListView 简单排序的实现 ListView 排序 怎样实现单击一下按升序,再单击一下按降序。
function CustomSortProc(Item1, Item2: TListItem; ColumnIndex: integer): integer; stdcall;
begin
if ColumnIndex = then
Result := CompareText(Item1.Caption,Item2.Caption)
else
Result := CompareText(Item1.SubItems[ColumnIndex-],Item2.SubItems[ColumnIndex-])
end; procedure TFrmSrvrMain.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
ListView1.CustomSort(@CustomSortProc,Column.Index);
end; =============================================================== //增加
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- downto 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[].Selected := True;
end; procedure TForm1.Button1Click(Sender: TObject); // 选择最后一条
begin
listview1.SetFocus;
listview1.Items[Listview1.Items.Count -].Selected := True;
end; //这是个通用的过程
procedure ListViewItemMoveUpDown(lv : TListView; Item : TListItem; MoveUp, SetFocus : Boolean);
var
DestItem : TListItem;
begin
if (Item = nil) or
((Item.Index - < ) and MoveUp) or
((Item.Index + >= lv.Items.Count) and (not MoveUp))
then Exit;
lv.Items.BeginUpdate;
try
if MoveUp then
DestItem := lv.Items.Insert(Item.Index - )
else
DestItem := lv.Items.Insert(Item.Index + );
DestItem.Assign(Item);
lv.Selected := DestItem;
Item.Free;
finally
lv.Items.EndUpdate;
end;
if SetFocus then lv.SetFocus;
DestItem.MakeVisible(False);
end; //此为调用过程,可以任意指定要移动的Item,下面是当前(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是要删除的列的序号,从0开始 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使用中的一些要点。以下以一个两列的ListView为例。
→增加一行:
with ListView1 do
begin
ListItem:=Items.Add;
ListItem.Caption:='第一列内容';
ListItem.SubItems.Add('第二列内容');
end;
→清空ListView1:
ListView1.Items.Clear;
→得到当前被选中行的行的行号以及删除当前行:
For i:= to ListView1.Items.Count- Do
If ListView1.Items[i].Selected then //i=ListView1.Selected.index
begin
ListView1.Items.Delete(i); //删除当前选中行
end;
当然,ListView有OnSelectItem事件,可以判断选择了哪行,用个全局变量把它赋值出来。
→读某行某列的操作:
Edit1.Text := listview1.Items[i].Caption; //读第i行第1列
Edit2.Text := listview1.Items[i].SubItems.strings[]; //读第i行第2列
Edit3.Text := listview1.Items[i].SubItems.strings[]; //读第i行第3列
以次类推,可以用循环读出整列。
→将焦点上移一行:
For i:= to ListView1.Items.Count- Do
If (ListView1.Items[i].Selected) and (i>) then
begin
ListView1.SetFocus;
ListView1.Items.Item[i-].Selected := True;
end;
不过在Delphi6中,ListView多了一个ItemIndex属性,所以只要
ListView1.SetFocus;
ListView1.ItemIndex:=;
就能设定焦点了。 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; 要想随时更改ListView 中某一行的字体颜色,要在ListView的 OnCustomDrawItem 的事件中书写相关的代码。例如 我想更改选中的某行字体的颜色,则需要在事件中写入下的代码: if item.Index = strtoint(edit1.Text) then //该条件是用于判断是否符合更改字体颜色的行的条件。
Sender.Canvas.Font.Color := clred;

如何设置网格线?

ViewStyle := vsReport;
GridLines := True;

Delphi界面篇之ListView控件的更多相关文章

  1. PyQt学习随笔:QtDesigner ListView控件列表项的初始化

    在QtDesigner中设计的界面中添加ListView控件后,是没办法添加需要在ListView控件中显示的列表项.由于ListView控件只是一个展示列表项的视图控件,实现了界面与数据的分离,其要 ...

  2. C#如何解决对ListView控件更新以及更新时界面闪烁问题

    第一个问题:如何更新ListView控件内容 很多时候运行窗体程序时,由于程序中使用了多线程加之操作不当,所以在对控件操作时会出现下面这样的异常:   这是因为我们在窗体中添加的控件都有属于自己的线程 ...

  3. 【Android基础】listview控件的使用(4)-----自定义布局的listview的使用

    前面我介绍了listview控件的不同用法,但是这些用法在实际的开发项目中是不足以满足需求的,因为前面的几种用法只能简单的显示文本信息,而且布局都比较单一,很难做出复杂的结果,在实际的开发项目中,90 ...

  4. ListView控件的理解——自洽理论

    写在前面的话: *标题中已经说明,是自洽理论.因此,有几率会有理解错误.但是,你不可以因此骂我. -我这个人经不起别人的批评,如果你批评我,我就,我就.... ## <第一行代码>读书笔记 ...

  5. ListView控件--2016年12月9日

    ListView属性 ListView   名称 说明 AccessKey 重写 WebControl.AccessKey 属性. 不支持将此属性设置 ListView 控件.(覆盖 WebContr ...

  6. 读取其他软件listview控件的内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. winform listview控件

    ListView控件 1.常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. (2) GridLines:设置 ...

  8. WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用

    WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用 转自:http://www.cnblogs.com/wuhuacong/arch ...

  9. Android中ListView 控件与 Adapter 适配器如何使用?

    一个android应用的成功与否,其界面设计至关重要.为了更好的进行android ui设计,我们常常需要借助一些控件和适配器.今天小编在android培训网站上搜罗了一些有关ListView 控件与 ...

随机推荐

  1. RESTful_基础知识

    目录 目录 前言 RESTful REST原则 REST的Web原则 分层系统原则 RESTful的实现 SOA 面向服务的体系结构 RPC样式 Web服务 RPC的实现过程 SOAP 简单对象访问协 ...

  2. 怎样用idhttpserver代替IIS让用户浏览html或下载文件 http://bbs.csdn.net/topics/360248674

      怎样用idhttpserver代替IIS让用户浏览html或下载文件 更多0分享到: 相关知识库: C# 虚拟现实(VR) Node.js 算法与数据结构     对我有用[0] 丢个板砖[0]  ...

  3. Vue作用域插槽:用作循环结构的模版

    一 项目结构 二 App组件 <template> <div id="app"> <!-- 子组件 --> <todos :list=&q ...

  4. MySQL 查询语句--------------进阶8:分页查询

    #进阶8:分页查询 /* 应用场景:要显示的数据,一页显示不全,需要分页提交sql请求 语法: select 查询列表 from 表 [join type] join 表2 on 连接条件 [wher ...

  5. Spring MVC处理

    1.首先,用户发送请求,DispatcherServlet会拦截请求,但DispatcherServlet收到请求后不进行处理,而对URL进行解析得到相应的URI(资源标识符). 2.Dispatch ...

  6. 同步GitHub上fork的项目

    最近在做“Python练习册,每天一个小程序”,fork了项目并贡献自己写的代码,项目还有其他人在贡献代码,每天都会更新,这就涉及到了自己fork的项目与原项目的同步更新问题,下面就是我最常用的方法. ...

  7. python参数的介绍

    一.函数1.为什么要使用函数?减少代码的冗余2.函数先定义后使用(相当于变量一样先定义后使用)3.函数的分类:内置函数:python解释器自带的,直接拿来用就行了自定义函数:根据自己的需求自己定义的函 ...

  8. MySQL数据类型-整型

    ​ MySQL支持SQL标准整数类型integer(或INT)和SMALLINT.作为标准的扩展,MySQL还支持整数类型TINYINT.MEDIUMINT和BIGINT. 类型 所占字节 有符号最小 ...

  9. eclipse的maven配置及本地仓库配置

    一.下载maven并解压 下载地址:http://maven.apache.org/download.cgi 解压后如下: 二.配置环境变量 配置MAVEN_HOME 再path中添加 安装成功 三. ...

  10. 二维码生成器,基于python,segno库

    import segno temp = input("Please enter value:") qr = segno.make(temp) qr.save("qrcod ...