Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Retrieving elements from a Grid in C#?

Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
Jason Dolinger
Guest


 

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
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adobe Photoshop Elements 6 & Adobe Premiere Elements 4 Jorge131 Vista music pictures video 12 05-27-2008 08:54 PM
Can't delete elements in folder Recent elements Gudmund Liebach Nielsen Vista General 1 05-05-2008 07:17 PM
Support for Adobe photoshop elements 5 or premier elements 3 on Vista 64 bits Sébastien DELAYRE Vista General 5 03-26-2007 09:57 AM
WPF Grid? john Avalon 0 11-19-2006 12:55 PM
Grid.Row Grid.Column set programatically at runtime craig kelly-soens www.XpectWorld.com Avalon 0 01-10-2006 03:52 PM








Vistax64.com 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 2005-2008

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 47 48 49 50