cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pearldrumbum
Frequent Visitor

Reading values in a comma-separated string and selecting matching items in a combobox

I have a multi-line text box that contains data in a basic comma-separated list that looks something like this:

ItemA, ItemC, ItemF,

I also have a combobox with a bunch of items to choose from - ItemA - ItemZ. I want to read all the values in the text box and have those items selected by default in the combobox. How can I accomplish this?

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

You can use the Split function to break the string down into the parts, then update its values to match the schema of the data in the combo box.

 

For example, if the Items property of the combo box is set to the collection ItemOptions, which is defined as

ClearCollect(
    ItemOptions;
    "ItemA"; "ItemB"; "ItemC"; "ItemD"; "ItemE"; "ItemF";
    "ItemG"; "ItemH"; "ItemI"; "ItemJ"; "ItemK"; "ItemL";
    "ItemM"; "ItemN"; "ItemO"; "ItemP"; "ItemQ"; "ItemR";
    "ItemS"; "ItemT"; "ItemU"; "ItemV"; "ItemW"; "ItemX";
    "ItemY"; "ItemZ")

That collection has items with a single property called 'Value'. So we can use the expression below to populate a collection that can be used as the DefaultSelectedItems of the combo box control.

ClearCollect(
    ItemDefaults;
    Filter(
        ShowColumns(
            AddColumns(
                Split(TextInput1.Text; ",");
                "Value";
                Trim(Result));
            "Value");
        Not(IsBlank(Value)) And Not(IsEmpty(Value))))

Breaking the above expression down:

  • It first splits the string around the comma separator
  • Then adds a new column (called Value, which matches the item options) that removes any leading and trailing spaces
  • Then selects (ShowColumns) only that column, since the other one is not needed anymore
  • Finally filters out all values that are empty (which you'll get if you have a trailing ',' separator in the input string)

The attached app shows this logic in action.

View solution in original post

3 REPLIES 3
CarlosFigueira
Power Apps
Power Apps

You can use the Split function to break the string down into the parts, then update its values to match the schema of the data in the combo box.

 

For example, if the Items property of the combo box is set to the collection ItemOptions, which is defined as

ClearCollect(
    ItemOptions;
    "ItemA"; "ItemB"; "ItemC"; "ItemD"; "ItemE"; "ItemF";
    "ItemG"; "ItemH"; "ItemI"; "ItemJ"; "ItemK"; "ItemL";
    "ItemM"; "ItemN"; "ItemO"; "ItemP"; "ItemQ"; "ItemR";
    "ItemS"; "ItemT"; "ItemU"; "ItemV"; "ItemW"; "ItemX";
    "ItemY"; "ItemZ")

That collection has items with a single property called 'Value'. So we can use the expression below to populate a collection that can be used as the DefaultSelectedItems of the combo box control.

ClearCollect(
    ItemDefaults;
    Filter(
        ShowColumns(
            AddColumns(
                Split(TextInput1.Text; ",");
                "Value";
                Trim(Result));
            "Value");
        Not(IsBlank(Value)) And Not(IsEmpty(Value))))

Breaking the above expression down:

  • It first splits the string around the comma separator
  • Then adds a new column (called Value, which matches the item options) that removes any leading and trailing spaces
  • Then selects (ShowColumns) only that column, since the other one is not needed anymore
  • Finally filters out all values that are empty (which you'll get if you have a trailing ',' separator in the input string)

The attached app shows this logic in action.

View solution in original post

Thank you! That worked perfectly. I was on the right track trying to use Split() but wasn't sure how to implement the AddColumns and ShowColumns functions to make it work.

Thank u som much,

 

looking for this for 1 year.

 

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,226)