Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi auto scroll through combobox

Tags:

delphi

I would like to know if there is a way to auto increment or scroll through a combobox.

For example every 30 seconds I want it to choose the next option in the combobox continuously until it gets to the last value, then it must go back to index 0 and continue from there.

The reason for this is that each value in my combobox contains a value that calls data from the database to display, as these screens will be unmanned I want the to automatically change without user input.

I added a timer and the following code and set the interval as advised below (30000)

procedure TForm3.Timer1Timer(Sender: TObject);
begin
if ComboBox1.Index < comboBox1.Index.MaxValue then
ComboBox1.Index := +1
else
ComboBox1.Index := 0;
end;

Thanks in advance.

like image 850
Silentdarkness Avatar asked Dec 05 '25 07:12

Silentdarkness


1 Answers

From a timer with Interval property set to 30000 ms I would use this code in its OnTimer tick event. For this code you must have at least one item in combo box:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ComboBox1.ItemIndex := (ComboBox1.ItemIndex + 1) mod ComboBox1.Items.Count;
end;
like image 195
TLama Avatar answered Dec 06 '25 19:12

TLama