Ask a Question

UserForms- TcxListBox Question

SOLVED
vik33
Occasional Contributor

UserForms- TcxListBox Question

Capture.PNGHi ,

This might be a simple task but i am having hard time selecting all items of TcxListBox at run time if a user checks on the checkbox (that says, check all items). I am having hardtime to make use of Selected or itemindex properties of TcxListBox and there is not much information available for the same.

 

All i am trying to accomplish is this :

If at run time, user checks on the checkbox then all items of a TcxListBox should get selected so that i can take the values of all of them and put them in an array. 

 

Please see the attached image.

7 REPLIES 7
Ryan_Moran
Valued Contributor

I did not see a method for it, and this is kind of sloppy looking by the way the control draws, but it is one way of handling it.

Where List_XLS would be your userform, and lstXLS would be your TcxListBox, and chkAll would be your checkbox with the OnClick handler of function "checkedall":

 

function checkedall(sender) {
    /*
      make sure multiselect is enabled
    */
    UserForms.List_XLS.lstXLS.MultiSelect = true;
    
    /*
      if checked then set selected of each item in the listbox
    */
    if (UserForms.List_XLS.chkAll.Checked){
      for (var c = 0; c < UserForms.List_XLS.lstXLS.Items.Count;c++) {
        UserForms.List_XLS.lstXLS.Selected(c) = true;
      }
    }
    
    /*
      if checked then remove selected of each item in the listbox
    */
    if (!UserForms.List_XLS.chkAll.Checked) {
      for (var c = 0; c < UserForms.List_XLS.lstXLS.Items.Count;c++) {
        UserForms.List_XLS.lstXLS.Selected(c) = false;
      }
    }
}

 


''-Praise the sun and Give Kudos.''
vik33
Occasional Contributor

Hi Ryan,

  

UserForms.List_XLS.lstXLS.Selected(c) = true;

 

was the key i was looking for. Because Selected returns true and false, i don't know for some reason, i couldn't think of assigning true and false to it.

 

It worked, many Thanks for your timely help.

Regards,

Vik

Ryan_Moran
Valued Contributor

No prob 🙂


''-Praise the sun and Give Kudos.''
HKosova
SmartBear Alumni (Retired)

By the way, one loop is enough if you use the Checked value instead of hard-coding true/false:

 

...
var state = UserForms.List_XLS.chkAll.Checked;

for (var c = 0; c < UserForms.List_XLS.lstXLS.Items.Count; c++) {
  UserForms.List_XLS.lstXLS.Selected(c) = state;
}

 


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

Yup, good point 🙂


''-Praise the sun and Give Kudos.''

Hi,

 

How do i get selected values of TcxListBox. 

 

I have created my own UserForms with controls.

Now i want to get all selected data in my python function.

 

Please refer my attachment. 

 

Hi,

 

Not the Python, but for JScript something like this should work:

for (var i = 0; i < UserForms.<Form>.<List>.Items.Count; i++)
  if (UserForms.<Form>.<List>.Selected(i))
    strValue = strValue + <separator> + UserForms.<Form>.<List>.Items.Items(i);
Regards,
  /Alex [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
================================
cancel
Showing results for 
Search instead for 
Did you mean: