cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gochix
Solution Sage
Solution Sage

Set varID = first Gallery item after gallery has been filtered.

Good evening,

 

Trying to set a variable on the first gallery item after i search something. 

Have a textinput bar and what i would like to achieve is OnChange event to set variable on first gallery item.

Tried to use First(Gallery.Allitems) or something like that but no luck. 

 

If any ideas please share.

Thanks

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @Gochix ,

 

Do you want to select the first item of the gallery?

If so , you could try this on the onselect property of your button control:

Select(Gallery1,1)

 

AAA.gif

 

Best Regards,

Wearsky

View solution in original post

Thanks, this also works. however it doesn't scroll back to top.. So i ended up with this code.

Resets gallery, goes back to top and selects first item in the gallery.

 

 

Set(SelectedItemID,First('Main Display'.AllItems).ID);
Reset('Main Display')

 

View solution in original post

5 REPLIES 5
BrianS
Super User
Super User

I put this code in the OnChange of a Text Input:

Set(var_test2,First(Gallery1.AllItems))

It did put the record in the variable. It is the entire record however. So to display it in a text field, you would need to use just one field (var_test2.Name).

If you only need one field from the record you could use

Set(var_test2,First(Gallery1.AllItems).Name)

to capture just that one field

@BrianS ,

Thanks, your solution works. It set's variable. However I'm trying to display the Display Form once variable is set, but form doesn't change.. Only once i manually select item from gallery as i have onselect event as Set(var_test2, ThisItem.ID) 

 

Set(SelectedItemID,First('Main Display'.AllItems).ID)

Couldn't use Reset(DisplayDetails); This is (Display Form). doesn't look like this works in the same way as gallery would reset..

I've managed to sort this by adding a button that will update everything on select event. It's also quicker to use button rather than allowing gallery to search every time the new text character is typed.. 

 

Only question would be is there a way to also set templatefill to go all the way back to top.. As now i have on button select that i will get first item selected if found. but if i scroll down a bit and do a search then templatefill will color the item somewhere in the middle of the gallery...

If(ThisItem.IsSelected,RGBA(255,255,1,0.2),RGBA(0,0,0,0))

v-xiaochen-msft
Community Support
Community Support

Hi @Gochix ,

 

Do you want to select the first item of the gallery?

If so , you could try this on the onselect property of your button control:

Select(Gallery1,1)

 

AAA.gif

 

Best Regards,

Wearsky

Thanks, this also works. however it doesn't scroll back to top.. So i ended up with this code.

Resets gallery, goes back to top and selects first item in the gallery.

 

 

Set(SelectedItemID,First('Main Display'.AllItems).ID);
Reset('Main Display')

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (1,647)