delphi - how do i get index of listview item where its subitem equal some string without using selected items? -


i use list view inside project wanted index of item finding subitem string , have listview item , subitem , item caption := name , subitem := id want find index of item sub item := id , how , searched while equations , didn't got 1 yet . reason need because subitem id have unique id , secure instead of using find item caption

you need loop through list view's items, looking @ proper subitem want match. instance, given tlistview 3 columns (a, b, , c), search through column b find something:

function tform1.findlistindex(const texttomatch: string): integer; var   i: integer; begin   := 0 listview1.items.count - 1     if listview1.items[i].subitems[1] = texttomatch       exit(i);   result := -1; end; 

of course, substitute own matching function (sametext, instance):

if sametext(listview1.items[i].subitems[1], texttomatch)    ...; 

if want search match in any sub-item, need nested loop:

function tform1.findlistindex(const texttomatch: string): integer; var   i, j: integer; begin   := 0 listview1.items.count - 1     j := 0 listview1.items[i].subitems.count - 1       if listview1.items[i].subitems[j] = texttomatch         exit(i);   result := -1; end; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -