Using checkbox in a canvas apps gallery

This article illustrates about using the checkbox inside a gallery in canvas apps

Step 1: Create a gallery and set the properties of the gallery as below:

Data source : Contacts
Layout: Title
Clear the default value in the title
GalleryProperty

Step 2: Add checkbox from the input options inside the gallery and set the “Text Property” of the checkbox to ‘Full Name’ from the Contact.
Now this will display the Contact’s Full Name next to the check box

checkbox

Step 3: Add the checked items in the gallery to a collection
This is done by setting the “OnCheck” property to “Collect(checkedcontacts,{name:Gallery1.Selected.’Full Name’})

checkedcollection

Step 4: Remove the items from the collection when the item in gallery is Unchecked
This is done by setting “OnUncheck” property to :
Remove(checkedcontacts,First(Filter(checkedcontacts,name = ThisItem.’Full Name’)),All)

Uncheck

Step 5: To test this, add a data table and set the items property as in the Image below.

Datatable

Step 6: Go to the fields property of the data table click edit and chose the field as below

DataField

 

Step 7: Play the app and test it by checking and unchecking the checkbox in a gallery and view the corresponding data in the data table

TestCheck

 

 

 

 

 

 

Thanks,
Shayan

 

 

Using IsBlank with Gallery Items to hide empty records

This post details about the use of Isblank function in power apps.

Scenario : A power apps user enters details such as name, phone and comments and adds them to a collection say “ContactInfo”.
The items from the collection is then displayed in the gallery.

Lets take a look at the below screen displaying records in a gallery where title is set to name and subtitle is set to phone.

galleryItemswithoutIsblank

Problem : The user can leave the name field as empty resulting the collection to not have any name, hence the gallery displays records with out name. This is because the items property of the gallery is simply set to the collection “ContactInfo”

Itemsinfo1

 

Requirement : The gallery should be filtered such that it displays only items that has name

Solution : Filter + IsBlank

The IsBlank function tests for a blank value or an empty string, whose result can be used to filter the items property of the gallery, in our case we need to check if there is a name in the collection”ContactInfo”, if yes then display the collection items in the gallery, otherwise do not display.

Notice after the Items property is set with the below function  the gallery will only display records which has a value for the name.
Filter(ContactInfo, !IsBlank(Name));

ItemsIsblank

 

 

 

Thanks,
Shayan

 

 

 

Highlighting the selected gallery item in Power Apps

This post details on highlighting the selected items in a Power Apps gallery.

Here are the steps to achieve this.
Step 1 : Go to make.powerapps.com
Select Apps and click New app and select Canvas

Step 2 : Choose the blank canvas, tablet layout from the template; this action will redirect to the Power Apps Studio

Step 3 : Click on the Insert action from the ribbon, select gallery with vertical layout and set the Items property of the gallery to ‘CustomGallerySample’ and in the layout select Title and subtitle.

sampleGallery

Step 4 : Select the gallery from the left hand pane and choose to click on the ‘Icons’ from the top command bar & select rectangle from the icons option.

addicons

Step 5 : After step 4 align the rectangle to the left corner of the gallery which should look similar to below image

galleryaftericon

Step 6 : Select the gallery and look for the ‘Template Fill’ property and in the formula bar enter ->   If(ThisItem.IsSelected, Color.LightGray, Color.White) and save.

gallerytemplatefill

Step 7 : Select the rectangle icon inside the gallery and look for the ‘Fill’ property and in the formula bar enter -> If(ThisItem.IsSelected, Color.Green, Color.White) and save.

Rectanglefill

Step 8: Save the App and click Play and see the selected items getting highlighted in action

highlighteditem

Thanks,
Shayan