Refering to elements of a grid by Name property

  • Thread starter Thread starter K Viltersten
  • Start date Start date
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.
 
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.
 
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!
 
Back
Top