# Solved: Delhi listbox item highlight



## nastechee (Feb 24, 2008)

Delphi4/5(Pascal)
I want to select/highlight an item in a listbox object which has just been transferred.

tried 'lisbAttSel.Selected[index]:= True;' but this gives 
'List index out of bounds(0)' error at runtime.
This is just after putting an item into the listbox so there should be an item at index = 0.
====================================================
procedure TForm1.btnAddAttClick(Sender: TObject);
// to transfer an item from one list box to another
var sTemp: string;
nTemp, tTemp: integer;
begin
nTemp:= lisbAvail.ItemIndex;
if (nTemp >= 0) then
begin
sTemp:= lisbAvail.Items.Strings[nTemp];
lisbAttSel.Items.Add( sTemp);
tTemp:= lisbAttSel.Items.Count;

lisbAttSel.Selected[tTemp-1]:= True; // Error at this line

lisbAvail.Items.Delete(nTemp);
end
else Application.MessageBox('No item selected'
,'Nothing selected', MB_OK);
end;
=====================================================

Any ideas please?

Phil


----------



## nastechee (Feb 24, 2008)

lisbAttSel.Selected[tTemp-1]:= True; // Error at this line

lisbAttSel.ItemIndex:=tTemp-1; //solves it

Phil


----------

