Ask a Question

How to iterate through items in a list box

hhagay
Contributor

How to iterate through items in a list box

Hello Community

 

I have a drop-down list (aka combo-box) with multiple items. I would like to get the items count and select one randomly.

 

Thank you 🙂

 

3 REPLIES 3
Bharadwaj
Contributor

 

function SelectItemFromListBox(listControl:OleVariant, listValue:string): boolean;
var 
i, itemIndex: integer;
begin
result := false;

itemIndex := -1;

for i := 0 to listControl.wItemCount - 1 do
begin
 if listControl.wItem[i] = Value then
 begin
  itemIndex := i;
  break;
 end; 
end;

if itemIndex < 0 then
begin
Log.Error('Item value ''' + VarToStr(listValue) + ''' not found in list control ' + VarToStr(listControl.FullName), nil, nil, nil, listControl.Picture);
exit;
end;

listControl.Keys('[Home]');

for i := 0 to itemIndex - 1 do
listControl.Keys('[Down]');
result := true;
end;

 

 

shankar_r
Community Hero

wItemCount - to get the list count.

wClickItem - to click the item based on the index or value.

 

More information, You can refer the @NisHera post.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

cancel
Showing results for 
Search instead for 
Did you mean: