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. 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 $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);
      }
    }
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    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);
      }
    }
    • Adagio's avatar
      Adagio
      Frequent Contributor

      Thank you, Helen! This is fantastic.

       

      Thank you

      Abhi

  • What output do you get from that Log.Message right above where your error occurs?