Ask a Question

TestComplete UserForms - TcxListBox issue

SOLVED
Adagio
Frequent Contributor

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;
      
    }
  } 
  
  

}

 

 

UsrForm.PNG

 

 

Thank you

Abhi

 

3 REPLIES 3
Marsha_R
Community Hero

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


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
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);
  }
}

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Adagio
Frequent Contributor

Thank you, Helen! This is fantastic.

 

Thank you

Abhi

cancel
Showing results for 
Search instead for 
Did you mean: