We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
Hello,
I have a listBox and need to select all the rows in the list after a checkbox is checked.
This is the piece of code that I'm using. I'm running into an issue at the line marked in bold. I've attached the snapshot of error as well. any help would be appreciated!
function UsrForm_cxCheckBoxAllFunctions_OnChange(Sender)
{
if(UserForms.UsrForm.cxCheckBoxAllFunctions.Checked){
Log.Message("List Length is: " +UserForms.UsrForm.cxListAllFunctions.Items.Count);
for(var i = 0; i< UserForms.UsrForm.cxListAllFunctions.Items.Count; i++){
Log.Message("UserForms.UsrForm.cxListAllFunctions.Selected("+i+") = " + UserForms.UsrForm.cxListAllFunctions.Selected(i));
UserForms.UsrForm.cxListAllFunctions.Selected(i) = true;
}
}else{
for(var i = 0; i< UserForms.UsrForm.cxListAllFunctions.Items.Count; i++){
UserForms.UsrForm.cxListAllFunctions.Selected(i) == false;
}
}
}
Thank you
Abhi
Hi Abhi,
JavaScript (not to be confused with JScript) does not support direct assignment to parameterized properties.
UserForms.UsrForm.cxListAllFunctions.Selected(i) = true;
You need to use the https://support.smartbear.com/testcomplete/docs/reference/language/javascript/set-method.html method instead:
UserForms.UsrForm.cxListAllFunctions.$set("Selected", i, true);
https://support.smartbear.com/testcomplete/docs/scripting/specifics/javascript.html#indexed-properties
By the way, you can make this code a bit simpler by using variables:
function UsrForm_cxCheckBoxAllFunctions_OnChange(Sender)
{
var form = UserForms.UsrForm;
var listBox = form.cxListAllFunctions;
var state = form.cxCheckBoxAllFunctions.Checked;
Log.Message("List Length is: " + listBox.Items.Count);
for (var i = 0; i < listBox.Items.Count; i++)
{
listBox.$set("Selected", i, state);
}
}Hi Abhi,
JavaScript (not to be confused with JScript) does not support direct assignment to parameterized properties.
UserForms.UsrForm.cxListAllFunctions.Selected(i) = true;
You need to use the https://support.smartbear.com/testcomplete/docs/reference/language/javascript/set-method.html method instead:
UserForms.UsrForm.cxListAllFunctions.$set("Selected", i, true);
https://support.smartbear.com/testcomplete/docs/scripting/specifics/javascript.html#indexed-properties
By the way, you can make this code a bit simpler by using variables:
function UsrForm_cxCheckBoxAllFunctions_OnChange(Sender)
{
var form = UserForms.UsrForm;
var listBox = form.cxListAllFunctions;
var state = form.cxCheckBoxAllFunctions.Checked;
Log.Message("List Length is: " + listBox.Items.Count);
for (var i = 0; i < listBox.Items.Count; i++)
{
listBox.$set("Selected", i, state);
}
}Thank you, Helen! This is fantastic.
Thank you
Abhi
What output do you get from that Log.Message right above where your error occurs?