cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Reference a Controls name?

Is there a way to access the name of a control?

 

Examples:

  • control 1 is named "sombrero"
  • If I copy it 100 times, I have "sombrero_1", "sombrero_2"..."sombrero_99"
  • I want to write a function for the X property of all sombreros like:
    • X = buffer.Text + sombrero.Width * Right(sombrero.ThisItem, 3)

I could be totally off here, and there is another way to this, to access the name of a control?


Thanks

4 REPLIES 4
Highlighted
Microsoft
Microsoft

Re: Reference a Controls name?

Hi seadude,

 

 

Apologies if I misunderstand you, but it seems like you're not only trying to get to a common property across multiple controls but also trying to reference a relative property of a control within one of it's properties - I'm not sure how you can do it the way you're trying to do it as I've never come across anything like a master object model you can navigate in PowerApps, including being able to reference a this instance of a control.

 

You can set all the control's X property to the same variable and then manipulate that, but if the manipulation also needs to reference a property of that specific control then I'm stumped.

 

so, eg: variable for property X;

  • Sombrero.X = varSombreroX
  • Sombrero_1.X = varSombreroX
  • ...
  • Sombrero_99.X = varSombreroX

 

To manipulate the X value for all these controls, you can then use UpdateContext() - so;

UpdateContext({varSombreroX: value})

 

will update the X property for all controls that have it, regardless of their name - but if you want "value" to be dependent on something within each specific control and therefore different for each control, (like the length of the text in that control), then I don't think you can reference it dynamically.

 

Will watch this thread with interest 🙂

 

RT

Highlighted
Super User
Super User

Re: Reference a Controls name?

@RusselThomas, thanks for the thoughtful reply. I actually think I made a mistake in my original post...

 

The goal is:

  • sombrero_41.X = sombrero.Width + buffer.Text * <thisSombrerosNumber> -1

 

I had "+" in the original post rather than " * ".

 

You could imagine: This would be a fast way to build a grid of items on the screen. Without this, you have to go into each Control and set the X Property of EVERY ONE like this:

 

  • sombrero_41.X = sobmbrero_40.X + sombrero.Width + buffer.Text

Is there another way to self-reference a Control?

Highlighted
Microsoft
Microsoft

Re: Reference a Controls name?

Hi seadude,

 

Not that I'm aware of 😞

 

Even in galleries, pre-populated controls that use auto-height/auto-spacing are rendered with the absolute name of the relative control it's being spaced from - and PowerApps doesn't accept strings as object references, so I'm really not sure it's possible.

 

Sorry I couldn't help - perhaps someone else knows a way, but if it turns out to be impossible, perhaps consider logging an idea on the Ideas forum? 🙂

 

Kind regards,

 

RT

 

 

 

 

Highlighted
Community Champion
Community Champion

Re: Reference a Controls name?

@seadude, it sounds like you want to duplicate controls and have their position respond according to their name.

 

This sounds like a use case for a gallery 🙂

 

Whenever you think of duplicating things, think of the gallery. There's a few ways to go about this, I'll share an interesting one.

 

Create a table with a column that specifies the X location you want.

Insert a control--we'll call it sombrero.

Set the X property of sombrero to the column that has the X location.

Repeat for Y if you want.

Set the TemplateSize of the Gallery to 0.

 

The position of the object will be relative to the dimensions of the gallery. You can do a lot of creative things this way.

Microsoft Employee
@8bitclassroom

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (6,875)