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

comboboxes - prevent duplicate selected value

Hello PowerApps community,

 

New to PowerApps here, I have 2 Comboboxes with identical items in a blank canvass screen. I would like to give user an error message if the selection in combobox2 is the same selection in combobox1.

 

Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
rubin_boer
Super User
Super User

hi @Away4mhome we have multiple people on this item for you. 

 

in my example you replace the following - highlighted in orange

Please make sure that you select the right column in the Fields

Consider the following:

Perform the following

  • ComboBox1 Items = theNameOfYourExcelDataSource
  • ComboBox2 Items = theNameOfYourExcelDataSource
  • label Text = "your message to user"
  • label Visible = ComboBox2.Selected.Value in ComboBox1.SelectedItems

This will indicate a item selected in combobox 2 which exists in combobox1

Preventing the scenario completely consider

  • ComboBox1 Items = theNameOfYourExcelDataSource
  • ComboBox2 Items = Filter(theNameOfYourExcelDataSource, Not(Value in ComboBox1.SelectedItems)

R

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.

View solution in original post

7 REPLIES 7
rubin_boer
Super User
Super User

hi @Away4mhome 

 

Consider the following:

  • datasource = __choices
  • Combobox1 
  • Combobox2
  • label to show error

Perform the following

  • ComboBox1 Items = __choices
  • ComboBox2 Items = __choices
  • label Text = "your message to user"
  • label Visible = ComboBox2.Selected.Value in ComboBox1.SelectedItems

This will indicate a item selected in combobox 2 which exists in combobox1

Preventing the scenario completely consider

  • ComboBox1 Items = __choices
  • ComboBox2 Items = Filter(__choices, Not(Value in ComboBox1.SelectedItems)

 

Both scenario assume you will allow multiselect

 

Hope this helps,

R

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.
JR-BejeweledOne
Super User
Super User

Are the ComboBoxes getting their items from a data source like a collection or did you manually type them into the items property?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
Abhilash_Swain
Super User
Super User

Hi @Away4mhome ,
Try like this.
On change property  of combobox 1,  clear and collect selected items. 
ClearCollect(test1,ComboBox1.SelectedItems.Value) [ Create a collection Test1.]

Abhilash_Swain_0-1646670522598.png

 

repeat the same for Combo box 2.

ClearCollect(test2,ComboBox2.SelectedItems.Value)

 

 

Below you can have a validation Label :- 
Concat(ForAll(test2, If(CountRows(Filter(test1,Value = ThisRecord.Value))>0,Concatenate(ThisRecord.Value,":-Duplicate Selected",Char(10)),Concatenate(ThisRecord.Value,":-Unique Selected",Char(10)))),Value)

Abhilash_Swain_1-1646670853862.png

 

Please give me a Thumbs up if I answered your question and mark it as a solution to help others.

Thanks

Abhi

 

 

The combobox items are coming from an excel data source, and I'm trying to avoid the user from making a duplicate selection.

JR-BejeweledOne
Super User
Super User

To build on the answer given by @rubin_boer , if you have manually typed your choices into the items property you can do the same thing like this:

 

Example:  Combbox1 Items ["Red", "Pink", "Blue", "Yellow"]

 

Combobox2 would be this:

 

 

 

Filter(["Red", "Pink", "Blue", "Yellow"], !(Value in ComboBox2.Selected.Value))

 

 

 

This will remove the selected item from the available choices in the second combo box



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
rubin_boer
Super User
Super User

hi @Away4mhome we have multiple people on this item for you. 

 

in my example you replace the following - highlighted in orange

Please make sure that you select the right column in the Fields

Consider the following:

Perform the following

  • ComboBox1 Items = theNameOfYourExcelDataSource
  • ComboBox2 Items = theNameOfYourExcelDataSource
  • label Text = "your message to user"
  • label Visible = ComboBox2.Selected.Value in ComboBox1.SelectedItems

This will indicate a item selected in combobox 2 which exists in combobox1

Preventing the scenario completely consider

  • ComboBox1 Items = theNameOfYourExcelDataSource
  • ComboBox2 Items = Filter(theNameOfYourExcelDataSource, Not(Value in ComboBox1.SelectedItems)

R

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.

the problem facing while using this solution 

If the user selected some people in first combo box . It will be removed from the second combo box

But If  the user again select the first combo box . And then when the user return the second combo box . If the 

selects  any option which was already selected . Again it will be counted as selected 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Users online (3,616)