By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,963 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

Refering to elements of a grid by Name property

P: n/a
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.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Oct 12 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"K Viltersten" wrote:
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.

--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy

Oct 13 '08 #2

P: n/a
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!

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
Oct 13 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.