Combox SelectRowWithText Not Working?

My code:

cmbPeriod.AddRow("1")
cmbPeriod.AddRow("2")
cmbPeriod.AddRow("3")
cmbPeriod.AddRow("4")
cmbPeriod.AddRow("5")
cmbPeriod.AddRow("6")
cmbPeriod.AddRow("7")
cmbPeriod.AddRow("8")
cmbPeriod.AddRow("9")
cmbPeriod.AddRow("10")

cmbPeriod.SelectRowWithText = Str(VolumeRefresh / 1000)

VolumeRefresh holds the value 2000 as an Integer.

When I run the code it fails to compile with the error:

This method cannot accept an assigned value (it lacks an Assigns parameter).

Am I doing something wrong? I want the combobox to have the string “2” preselected/shown by default.

try

cmbPeriod.SelectRowWithText( Str(VolumeRefresh / 1000) )

2 Likes

argh - can’t believe i never thought of that… thanks!

If your Code is not just an example, the following may be a tiny bit faster:

cmbPeriod.SelectedRowIndex = VolumeRefresh / 1000 - 1

But actually I just thought, why search for the string when the index can be calculated? :wink:

1 Like

hmmm, this never occurred to me actually. as i know the order of the items in the combo box i could use your method - thanks!

1 Like