Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
7 years ago

TestComplete UserForms - TcxListBox issue

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. ...
  • HKosova's avatar
    7 years ago

    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 $set method instead:

    UserForms.UsrForm.cxListAllFunctions.$set("Selected", i, true);

    JavaScript Specifics - 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);
      }
    }