Refering to elements of a grid by Name property

K

K Viltersten

I have a Grid object with some controls
added to it. When i need to access any
of them, i refer to them by the index.

grid.Children[3].Content = "text";

As you surely understand, it's a smelly
solution and i'd like to change it.

How can i refer to the elements by
their names? The below doesn't compile
since the index needs to be int type.

grid.Children["MyStuff"];

Any advise would be great.
 
C

Ciaran O''Donnell

Sadly this controls collection for windows controls and I believe webcontrols
is a List, not a Dictionary so there is no way to refer to the controls by
any kind of key.
You could write an extension (or normal) method which will search the
collection for the child with the particular name your looking for.
 
K

K Viltersten

Sadly this controls collection for windows controls and I believe
webcontrols is a List, not a Dictionary so there is no way to
refer to the controls by any kind of key. You could write an
extension (or normal) method which will search the collection for
the child with the particular name your looking for.

Yes, that's what i did. I just wanted to make the code even more
"clever". I guess, i was done already.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top