listview要搜尋SubItems裡面的值 |
答題得分者是:Fishman
|
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
|
ghyghost
一般會員 發表:3 回覆:8 積分:2 註冊:2003-03-16 發送簡訊給我 |
|
solnone
中階會員 發表:2 回覆:97 積分:69 註冊:2003-05-06 發送簡訊給我 |
|
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
引言: ghyghost form1.ListView1.FindCaption ??回ghyghost這個好像只找上面item確沒找到SubItem <>< face="Verdana, Arial, Helvetica">引言: solnone 找某一個 SubItem if ListView1.Items.Item[0].SubItems.IndexOf('line1') > -1 then ; 找 SubItems if Pos('a', ListView1.Items.Item[0].SubItems.Text) > 0 then ; 回solnone那要搜尋整個ListView1就要寫回圈了是嗎? 再請問既然有FindCaption可以找item那有沒有找SubItem的函式或偷雞方式呢?
------
====================== 昏睡~ 不昏睡~ 不由昏睡~ |
aquarius
資深會員 發表:3 回覆:347 積分:330 註冊:2003-05-21 發送簡訊給我 |
|
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi:
procedure TForm1.Button1Click(Sender: TObject); var Index : Integer; begin if (ListView1.Items.Item[0].SubItems AS TStringList).Find(Edit1.Text,Index) then ShowMessage(IntToStr(Index)); end;小弟才疏學淺,若有謬誤請不吝指教 ---------------------- 新手上路,請多多指教 ----------------------
------
Fishman |
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
引言: aquarius 請參考 TListView 的 FindData 及 OnDataFind回aquarius 引言: procedure TForm1.ListViewDataFind(Sender: TObject; Find: TItemFind; const FindString: String; const FindPosition: TPoint; FindData: Pointer; StartIndex: Integer; Direction: TSearchDirection; Wrap: Boolean; var Index: Integer); //OnDataFind gets called in response to calls to FindCaption, FindData, //GetNearestItem, etc. It also gets called for each keystroke sent to the //ListView (for incremental searching) var I: Integer; Found: Boolean; begin I := StartIndex; if (Find = ifExactString) or (Find = ifPartialString) then begin repeat if (I = FIDList.Count-1) then if Wrap then I := 0 else Exit; Found := Pos(UpperCase(FindString), UpperCase(ShellItem(I)^.DisplayName)) = 1; Inc(I); until Found or (I = StartIndex); if Found then Index := I-1; end; end;還是只有找到item而非subitem <>< face="Verdana, Arial, Helvetica">引言: Fishman procedure TForm1.Button1Click(Sender: TObject); var Index : Integer; begin if (ListView1.Items.Item[0].SubItems AS TStringList).Find(Edit1.Text,Index) then ShowMessage(IntToStr(Index)); end; 回Fishman這個小弟測不出來,他都沒有ShowMessage to me!! 冒昧問一下!!非常光碟....共人是嗯是裡台 >
------
====================== 昏睡~ 不昏睡~ 不由昏睡~ |
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi: 小程式,供你參考
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) Button1: TButton; ListView1: TListView; ComboBox1: TComboBox; procedure Button1Click(Sender: TObject); procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1 : TForm1; Index : Integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var Id : Integer; begin if (ListView1.Items.Item[Index].SubItems AS TStringList).Find(ComboBox1.Text,Id) then ShowMessage(IntToStr(Id)) else ShowMessage('No Match Data Found !!'); end; procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean); VAR I : Integer; begin IF Selected THEN BEGIN Index := Item.Index; ComboBox1.Items.Clear; FOR I := 0 TO Item.SubItems.Count - 1 DO BEGIN ComboBox1.Items.Add(Item.SubItems.Strings[I]); END; ComboBox1.ItemIndex := 0; END; end; procedure TForm1.FormCreate(Sender: TObject); begin ListView1.OnSelectItem(ListView1,ListView1.Items.Item[0],True); end; end.-------------------------------- 小弟才疏學淺,若有謬誤請不吝指教 --------------------------------
------
Fishman |
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi:
procedure TForm1.Button1Click(Sender: TObject); var I : Integer; begin FOR I := 0 TO ListView1.Items.Item[Index].SubItems.Count - 1 DO BEGIN IF POS(ComboBox1.Text,ListView1.Items.Item[Index].SubItems.Strings[I]) > 0 THEN BEGIN ShowMessage(ListView1.Items.Item[Index].SubItems.Strings[I]); Exit; END; END; ShowMessage('No Match Data Found !!'); end;-------------------------------- 小弟才疏學淺,若有謬誤請不吝指教 --------------------------------
------
Fishman |
ko
資深會員 發表:28 回覆:785 積分:444 註冊:2002-08-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |