﻿{"id":36148,"date":"2012-04-04T15:07:43","date_gmt":"2012-04-04T07:07:43","guid":{"rendered":"http:\/\/www.lanmaowang.com\/word\/?p=36148"},"modified":"2015-04-09T00:23:44","modified_gmt":"2015-04-08T16:23:44","slug":"delphi-listview-guinness-basic-usage","status":"publish","type":"post","link":"http:\/\/www.lanmaowang.com\/?p=36148","title":{"rendered":"Delphi ListView\u57fa\u672c\u7528\u6cd5\u5927\u5168"},"content":{"rendered":"<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">Delphi ListView\u57fa\u672c\u7528\u6cd5\u5927\u5168<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u589e\u52a0\u9879\u6216\u5217(\u5b57\u6bb5)<\/p>\n<pre class=\"brush:delphi;toolbar:false\">ListView1.Clear;\r\nListView1.Columns.Clear;\r\nListView1.Columns.Add;\r\nListView1.Columns.Add;\r\nListView1.Columns.Add;\r\nListView1.Columns.Items[0].Caption:=&#39;id&#39;;\r\nListView1.Columns.Items[1].Caption:=&#39;type&#39;;\r\nListView1.Columns.Items[2].Caption:=&#39;title&#39;;\r\nListView1.Columns.Items[2].Width:=300;\r\nListview1.ViewStyle:=vsreport;\r\nListview1.GridLines:=true;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6ce8:\u6b64\u5904\u4ee3\u7801\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u53ef\u89c6\u5316\u7f16\u8f91\u5668\u4e2d\u5b8c\u6210,<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\u4e5f\u53ef\u5199\u6210\u4ee5\u4e0b\u8fd9\u6837<\/p>\n<pre class=\"brush:delphi;toolbar:false\">begin\r\n&nbsp;&nbsp;with&nbsp;listview1&nbsp;do\r\n&nbsp;&nbsp;&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Columns.Add;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Columns.Add;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Columns.Add;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ViewStyle:=vsreport;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GridLines:=true;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;columns.items[0].caption:=&#39;\u8fdb\u7a0b\u540d&#39;;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;columns.items[1].caption:=&#39;\u8fdb\u7a0bID&#39;;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;columns.items[2].caption:=&#39;\u8fdb\u7a0b\u6587\u4ef6\u8def\u5f84&#39;;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Columns.Items[0].Width:=100;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Columns.Items[1].Width:=100;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Columns.Items[2].Width:=150;\r\n&nbsp;&nbsp;&nbsp;&nbsp;end\r\nend;<\/pre>\n<pre class=\"brush:delphi;toolbar:false\">\/\/\u589e\u52a0\u8bb0\u5f55\r\nwith&nbsp;listview1.items.add&nbsp;do\r\nbegin\r\n&nbsp;&nbsp;caption:=&#39;1212&#39;;\r\n&nbsp;&nbsp;subitems.add(&#39;hh1&#39;);\r\n&nbsp;&nbsp;subitems.add(&#39;hh2&#39;);\r\nend;<\/pre>\n<pre class=\"brush:delphi;toolbar:false\">\/\/\u5220\u9664\r\nlistview1.items.delete(0);<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u4ece\u6570\u636e\u5e93\u8868\u91cc\u8bfb\u53d6\u6570\u636e\u5199\u5165Listview<\/p>\n<pre class=\"brush:delphi;toolbar:false\">var\r\nTitem:Tlistitem;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6b64\u5904\u4e00\u5b9a\u8981\u9884\u5b9a\u4e49\u4e34\u65f6\u8bb0\u5f55\u5b58\u50a8\u53d8\u91cf.\r\nbegin\r\n&nbsp;&nbsp;ListView1.Items.Clear;\r\n&nbsp;&nbsp;with&nbsp;adoquery1&nbsp;do\r\n&nbsp;&nbsp;&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql.Clear;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql.Add(&#39;select&nbsp;spmc,jg,sl&nbsp;from&nbsp;kcxs&#39;);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Open;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListView1.Items.Clear;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;not&nbsp;eof&nbsp;do\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Titem:=ListView1.Items.add;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Titem.Caption:=FieldByName(&#39;spmc&#39;).Value;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Titem.SubItems.Add(FieldByName(&#39;sl&#39;).Value);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Titem.SubItems.Add(FieldByName(&#39;jg&#39;).Value);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;\r\n&nbsp;&nbsp;&nbsp;&nbsp;end;\r\nend;<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u5220\u9664<\/p>\n<pre class=\"brush:delphi;toolbar:false\">ListView1.DeleteSelected;<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u5982\u4f55\u53d6\u5f97ListView\u4e2d\u9009\u4e2d\u884c\u7684\u67d0\u4e00\u5217\u7684\u503c<\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;TForm1.Button2Click(Sender:&nbsp;TObject);\r\nbegin\r\n&nbsp;&nbsp;ShowMessage(ListView1.Selected.SubItems.Strings[1]);&nbsp;\/\/\u8fd4\u56de\u9009\u4e2d\u884c\u7b2c\u4e09\u5217\u4e2d\u7684\u503c\r\nend;<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">showMessage(listView1.Selected.Caption);&nbsp;&nbsp; \/\/\u8fd4\u56de\u9009\u4e2d\u884c\u7b2c\u4e00\u5217\u7684\u503c.<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\u7b2c1\u5217\u7684\u503c\uff1a --&gt;&gt;&gt; ListView1.Selected.Caption&nbsp;&nbsp;<br \/>\u7b2ci\u5217\u7684\u503c(i&gt;1):--&gt;&gt;&gt; ListView1.Selected.SubItems.Strings[i]<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">ListView1.Items.Item[1].SubItems.GetText); \/\/\u53d6\u5f97listview\u67d0\u884c\u67d0\u5217\u7684\u503c<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">Edit2.Text := listview1.Items[i].SubItems.strings[0];&nbsp;&nbsp; \/\/\u8bfb\u7b2ci\u884c\u7b2c2\u5217<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\u8fd4\u56de\u9009\u4e2d\u884c\u6240\u6709\u5b50\u5217\u503c.\u662f\u4ee5\u56de\u8f66\u7b26\u5206\u5f00\u7684\uff0c\u4f60\u8fd8\u8981\u4ece\u4e2d\u5265\u79bb\u51fa\u6765\u4f60\u8981\u7684\u5b50\u5217\u7684\u503c\u3002<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">showMessage(ListView1.Selected.SubItems.GetText);&nbsp;&nbsp;<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">ListView \u7b80\u5355\u6392\u5e8f\u7684\u5b9e\u73b0<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">ListView \u6392\u5e8f<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\u600e\u6837\u5b9e\u73b0\u5355\u51fb\u4e00\u4e0b\u6309\u5347\u5e8f,\u518d\u5355\u51fb\u4e00\u4e0b\u6309\u964d\u5e8f\u3002<\/p>\n<pre class=\"brush:delphi;toolbar:false\">function&nbsp;CustomSortProc(Item1,&nbsp;Item2:&nbsp;TListItem;&nbsp;ColumnIndex:&nbsp;integer):&nbsp;integer;&nbsp;stdcall;\r\nbegin\r\n&nbsp;&nbsp;if&nbsp;ColumnIndex&nbsp;=&nbsp;0&nbsp;then\r\n&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;CompareText(Item1.Caption,Item2.Caption)\r\n&nbsp;&nbsp;else\r\n&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;CompareText(Item1.SubItems[ColumnIndex-1],Item2.SubItems[ColumnIndex-1])\r\nend;\r\n\r\nprocedure&nbsp;TFrmSrvrMain.ListView1ColumnClick(Sender:&nbsp;TObject;Column:&nbsp;TListColumn);\r\nbegin\r\n&nbsp;&nbsp;ListView1.CustomSort(@CustomSortProc,Column.Index);\r\nend;<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">===============================================================<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u589e\u52a0<\/p>\n<pre class=\"brush:delphi;toolbar:false\">i&nbsp;:=&nbsp;ListView1.Items.Count;\r\nwith&nbsp;ListView1&nbsp;do\r\n&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListItem:=Items.Add;\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListItem.Caption:=&nbsp;IntToStr(i);\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListItem.SubItems.Add(&#39;\u7b2c&nbsp;&#39;+IntToStr(i)+&#39;&nbsp;\u884c&#39;);\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListItem.SubItems.Add(&#39;\u7b2c\u4e09\u5217\u5185\u5bb9&#39;);\r\n&nbsp;&nbsp;end;<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u6309\u6807\u9898\u5220\u9664<\/p>\n<pre class=\"brush:delphi;toolbar:false\">for&nbsp;i:=ListView1.Items.Count-1&nbsp;downto&nbsp;0&nbsp;Do\r\nif&nbsp;ListView1.Items[i].Caption&nbsp;=&nbsp;Edit1.Text&nbsp;then\r\nbegin\r\nListView1.Items.Item[i].Delete();&nbsp;\/\/\u5220\u9664\u5f53\u524d\u9009\u4e2d\u884c\r\nend;<\/pre>\n<p style=\"color: rgb(34, 34, 34); font-family: SimSun, Arial, Verdana, sans-serif; font-size: 14px; line-height: 19px; white-space: normal;\">\/\/\u9009\u4e2d\u4e00\u884c<\/p>\n<pre class=\"brush:delphi;toolbar:false\">if&nbsp;ListView1.Selected&nbsp;&lt;&gt;&nbsp;nil&nbsp;then\r\nEdit1.Text&nbsp;:=&nbsp;ListView1.Selected.Caption;<\/pre>\n<pre class=\"brush:delphi;toolbar:false\">\/\/&nbsp;listview1.Items[Listview1.Items.Count&nbsp;-1].Selected&nbsp;:=&nbsp;True;\r\n\/\/&nbsp;listview1.Items[Listview1.Items.Count&nbsp;-1].MakeVisible(True);\r\nprocedure&nbsp;TForm1.Button2Click(Sender:&nbsp;TObject);&nbsp;\/\/&nbsp;\u9009\u62e9\u7b2c\u4e00\u6761\r\nbegin\r\nlistview1.SetFocus;\r\nlistview1.Items[0].Selected&nbsp;:=&nbsp;True;\r\nend;\r\nprocedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);&nbsp;\/\/&nbsp;\u9009\u62e9\u6700\u540e\u4e00\u6761\r\nbegin\r\nlistview1.SetFocus;\r\nlistview1.Items[Listview1.Items.Count&nbsp;-1].Selected&nbsp;:=&nbsp;True;\r\nend;\r\n\/\/\u8fd9\u662f\u4e2a\u901a\u7528\u7684\u8fc7\u7a0b\r\nprocedure&nbsp;ListViewItemMoveUpDown(lv&nbsp;:&nbsp;TListView;&nbsp;Item&nbsp;:&nbsp;TListItem;&nbsp;MoveUp,&nbsp;SetFocus&nbsp;:&nbsp;Boolean);\r\nvar\r\nDestItem&nbsp;:&nbsp;TListItem;\r\nbegin\r\nif&nbsp;(Item&nbsp;=&nbsp;nil)&nbsp;or\r\n((Item.Index&nbsp;-&nbsp;1&nbsp;&lt;&nbsp;0)&nbsp;and&nbsp;MoveUp)&nbsp;or\r\n((Item.Index&nbsp;+&nbsp;1&nbsp;&gt;=&nbsp;lv.Items.Count)&nbsp;and&nbsp;(not&nbsp;MoveUp))\r\nthen&nbsp;Exit;\r\nlv.Items.BeginUpdate;\r\ntry\r\nif&nbsp;MoveUp&nbsp;then\r\nDestItem&nbsp;:=&nbsp;lv.Items.Insert(Item.Index&nbsp;-&nbsp;1)\r\nelse\r\nDestItem&nbsp;:=&nbsp;lv.Items.Insert(Item.Index&nbsp;+&nbsp;2);\r\nDestItem.Assign(Item);\r\nlv.Selected&nbsp;:=&nbsp;DestItem;\r\nItem.Free;\r\nfinally\r\nlv.Items.EndUpdate;\r\nend;\r\nif&nbsp;SetFocus&nbsp;then&nbsp;lv.SetFocus;\r\nDestItem.MakeVisible(False);\r\nend;<\/pre>\n<p>\/\/\u6b64\u4e3a\u8c03\u7528\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4efb\u610f\u6307\u5b9a\u8981\u79fb\u52a8\u7684Item\uff0c\u4e0b\u9762\u662f\u5f53\u524d(Selected)Item<\/p>\n<pre class=\"brush:delphi;toolbar:false\">ListViewItemMoveUpDown(ListView1,&nbsp;ListView1.Selected,&nbsp;True,&nbsp;True);\/\/\u4e0a\u79fb\r\nListViewItemMoveUpDown(ListView1,&nbsp;ListView1.Selected,&nbsp;False,&nbsp;True);\/\/\u4e0b\u79fb<\/pre>\n<p><\/p>\n<p>TListView\u7ec4\u4ef6\u4f7f\u7528\u65b9\u6cd5<\/p>\n<p>\u5f15\u7528CommCtrl\u5355\u5143<\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);\r\nbegin\r\n&nbsp;&nbsp;ListView_DeleteColumn(MyListView.Handle,&nbsp;i);\/\/i\u662f\u8981\u5220\u9664\u7684\u5217\u7684\u5e8f\u53f7\uff0c\u4ece0\u5f00\u59cb\r\nend;<\/pre>\n<p>\u7528LISTVIEW\u663e\u793a\u8868\u4e2d\u7684\u4fe1\u606f\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;viewchange(listv:tlistview;table:tcustomadodataset;var&nbsp;i:integer);\r\nbegin\r\n&nbsp;&nbsp;tlistview(listv).Items.BeginUpdate;&nbsp;{listv:listview\u540d}\r\n&nbsp;&nbsp;try\r\n&nbsp;&nbsp;&nbsp;&nbsp;tlistview(listv).Items.Clear;\r\n&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;table&nbsp;do&nbsp;{table&nbsp;or&nbsp;query\u540d}\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;active:=true;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;first;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;not&nbsp;eof&nbsp;do\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listitem:=tlistview(listv).Items.add;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listitem.Caption:=trim(table.fields[i].asstring);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;listitem.ImageIndex:=8;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;\r\n&nbsp;&nbsp;finally\r\n&nbsp;&nbsp;&nbsp;&nbsp;tlistview(listv).Items.EndUpdate;\r\n&nbsp;&nbsp;end;\r\nend;<\/pre>\n<p><\/p>\n<p>ListView\u4f7f\u7528\u4e2d\u7684\u4e00\u4e9b\u8981\u70b9\u3002\u4ee5\u4e0b\u4ee5\u4e00\u4e2a\u4e24\u5217\u7684ListView\u4e3a\u4f8b\u3002<\/p>\n<p>\u2192\u589e\u52a0\u4e00\u884c\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">with&nbsp;ListView1&nbsp;do\r\nbegin\r\n&nbsp;&nbsp;ListItem:=Items.Add;\r\n&nbsp;&nbsp;ListItem.Caption:=&#39;\u7b2c\u4e00\u5217\u5185\u5bb9&#39;;\r\n&nbsp;&nbsp;ListItem.SubItems.Add(&#39;\u7b2c\u4e8c\u5217\u5185\u5bb9&#39;);\r\nend;<\/pre>\n<p>\u2192\u6e05\u7a7aListView1\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">ListView1.Items.Clear;<\/pre>\n<p>\u2192\u5f97\u5230\u5f53\u524d\u88ab\u9009\u4e2d\u884c\u7684\u884c\u7684\u884c\u53f7\u4ee5\u53ca\u5220\u9664\u5f53\u524d\u884c\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">For&nbsp;i:=0&nbsp;to&nbsp;ListView1.Items.Count-1&nbsp;Do\r\n&nbsp;&nbsp;If&nbsp;ListView1.Items[i].Selected&nbsp;then&nbsp;\/\/i=ListView1.Selected.index\r\n&nbsp;&nbsp;&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListView1.Items.Delete(i);&nbsp;\/\/\u5220\u9664\u5f53\u524d\u9009\u4e2d\u884c\r\n&nbsp;&nbsp;&nbsp;&nbsp;end;<\/pre>\n<p>\u5f53\u7136\uff0cListView\u6709OnSelectItem\u4e8b\u4ef6,\u53ef\u4ee5\u5224\u65ad\u9009\u62e9\u4e86\u54ea\u884c,\u7528\u4e2a\u5168\u5c40\u53d8\u91cf\u628a\u5b83\u8d4b\u503c\u51fa\u6765\u3002<\/p>\n<p>\u2192\u8bfb\u67d0\u884c\u67d0\u5217\u7684\u64cd\u4f5c\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">Edit1.Text&nbsp;:=&nbsp;listview1.Items[i].Caption;&nbsp;\/\/\u8bfb\u7b2ci\u884c\u7b2c1\u5217\r\nEdit2.Text&nbsp;:=&nbsp;listview1.Items[i].SubItems.strings[0];&nbsp;\/\/\u8bfb\u7b2ci\u884c\u7b2c2\u5217\r\nEdit3.Text&nbsp;:=&nbsp;listview1.Items[i].SubItems.strings[1];&nbsp;\/\/\u8bfb\u7b2ci\u884c\u7b2c3\u5217<\/pre>\n<p>\u4ee5\u6b21\u7c7b\u63a8\uff0c\u53ef\u4ee5\u7528\u5faa\u73af\u8bfb\u51fa\u6574\u5217\u3002<\/p>\n<p>\u2192\u5c06\u7126\u70b9\u4e0a\u79fb\u4e00\u884c\uff1a<\/p>\n<pre class=\"brush:delphi;toolbar:false\">For&nbsp;i:=0&nbsp;to&nbsp;ListView1.Items.Count-1&nbsp;Do\r\nIf&nbsp;(ListView1.Items[i].Selected)&nbsp;and&nbsp;(i&gt;0)&nbsp;then\r\n&nbsp;&nbsp;begin\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListView1.SetFocus;\r\n&nbsp;&nbsp;&nbsp;&nbsp;ListView1.Items.Item[i-1].Selected&nbsp;:=&nbsp;True;\r\n&nbsp;&nbsp;end;<\/pre>\n<p>\u4e0d\u8fc7\u5728Delphi6\u4e2d\uff0cListView\u591a\u4e86\u4e00\u4e2aItemIndex\u5c5e\u6027\uff0c\u6240\u4ee5\u53ea\u8981<\/p>\n<pre class=\"brush:delphi;toolbar:false\">ListView1.SetFocus;\r\nListView1.ItemIndex:=3;<\/pre>\n<p>\u5c31\u80fd\u8bbe\u5b9a\u7126\u70b9\u4e86\u3002<\/p>\n<p>Delphi\u7684listview\u80fd\u5b9e\u73b0\u4ea4\u66ff\u989c\u8272\u4e48\uff1f<\/p>\n<pre class=\"brush:delphi;toolbar:false\">procedure&nbsp;TForm1.ListView1CustomDrawItem(Sender:&nbsp;TCustomListView;&nbsp;Item:&nbsp;TListItem;&nbsp;State:&nbsp;TCustomDrawState;var&nbsp;DefaultDraw:&nbsp;Boolean);\r\nvar\r\ni:&nbsp;integer;\r\nbegin\r\n&nbsp;&nbsp;i:=&nbsp;(Sender&nbsp;as&nbsp;TListView).Items.IndexOf(Item);\r\n&nbsp;&nbsp;if&nbsp;odd(i)&nbsp;then\r\n&nbsp;&nbsp;&nbsp;&nbsp;sender.Canvas.Brush.Color:=&nbsp;$02E0F0D7\r\n&nbsp;&nbsp;else&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;sender.Canvas.Brush.Color:=&nbsp;$02F0EED7;\r\n&nbsp;&nbsp;Sender.Canvas.FillRect(Item.DisplayRect(drIcon));\r\nend;<\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delphi ListView\u57fa\u672c\u7528\u6cd5\u5927\u5168 \/\/\u589e\u52a0\u9879\u6216\u5217(\u5b57\u6bb5) ListView1.Clear; List [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":36149,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[193],"tags":[198,199],"_links":{"self":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36148"}],"collection":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36148"}],"version-history":[{"count":3,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36148\/revisions"}],"predecessor-version":[{"id":36318,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/posts\/36148\/revisions\/36318"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=\/wp\/v2\/media\/36149"}],"wp:attachment":[{"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36148"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lanmaowang.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}