Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Retrieving elements from a Grid in C#?

 
 
Old 01-10-2006   #1 (permalink)
Jason Dolinger


 
 

Retrieving elements from a Grid in C#?

Let's say I have a grid defined in XAML with 2 rows and 2 columns, with
a button in each cell defined by the grid:

<Grid x:Name="myGrid" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Grid.Row="0" Grid.Column="0" />
<Button Grid.Row="0" Grid.Column="1" />
<Button Grid.Row="1" Grid.Column="0" />
<Button Grid.Row="1" Grid.Column="1" />
</Grid>


My question is, can I programmatically get a reference to a particular
button object, given the row and column coordinates?

For example, I'd love to be able to do this:

Button buttonReference = myGrid.Children.get(0, 0);

and have it return the button at 0,0 in the grid. While inspecting the
API I can't seem to find something that would give me this desired
functionality. System.Windows.Controls.Grid has a property Children
(inherited from Panel) which returns a UIElementCollection. From there,
the best you can do it get an Enumerator and loop through the children.
There must be a way to pick out a single one, right? I'm going for
performance as I will be updating the content of each grid child quite
frequently, and I simply can't afford to enumerate the entire Children
collection each time.

Anyone found anything that may help?

Regards,
Jason

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Adobe Photoshop Elements 6 & Adobe Premiere Elements 4 Vista music pictures video
Can't delete elements in folder Recent elements Vista General
Support for Adobe photoshop elements 5 or premier elements 3 on Vista 64 bits Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46