Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Modify listbox with checkboxes

Avatar

Avatar
Level 1
MacGrubR
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile

Avatar
Level 1
MacGrubR
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile
MacGrubR
Level 1

03-08-2015

Hello,


I'm creating a form for our company to use for equipment requests.  I have a section with checkboxes and a listbox.  The listbox is a summary field which shows the user which items they've selected and what the cost will be.  The desired behavior is for the checkbox to add an item to a listbox, and when the checkbox is unchecked it removes that item from the listbox.  Adding an item works great (ListBox.addItem("Display Text","1"), however I need help with the logic for removing the item from the listbox.  Initially I tried ListBox.deleteItem(x), but it doesn't work the way I need it to.  I think the issue is deleting items by their index number.  For example:

Objects:

ListBox2

CheckboxA

if (CheckboxA.rawValue != 0 ){

  ListBox2.addItem("Chair - $200","0");

  }else {

  ListBox2.deleteItem(0);

  }

CheckboxB

if (CheckboxB.rawValue != 0 ){

  ListBox2.addItem("Desk- $300","1");

  }else {

  ListBox2.deleteItem(1);

  }

CheckboxC

if (CheckboxC.rawValue != 0 ){

  ListBox2.addItem("Trashcan - $10","2");

  }else {

  ListBox2.deleteItem(2);

  }

The problem is if you Check CheckboxA and CheckboxB and then uncheck CheckboxA it throws the index off and the checkboxes no longer remove the right item.  Is there a way to delete an item from a listbox by using it's display value rather than index?  Is there another way of going about this?

Thanks,

Tom

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

270 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

08-08-2015

Hi Tom,

You can loop though the items testing for one with a specific value, in your case "0", "1", "2" with this code (for ChecboxB)

 

if (CheckboxB.rawValue != 0 ){

    ListBox2.addItem("Desk- $300","1");

}

else {

    for (var i = 0; i < ListBox2.length; i++) {

        if (ListBox2.boundItem(ListBox2.getDisplayItem(i)) == "1") {

     ListBox2.deleteItem(i);

            break;

     }

  }

}

Regards

Bruce