C# WPF
XAML
I have a grid of 3 rows and 3 columns (9 cells). Each cell has numbers. When I click on one cell, how do I retrieve the numbers in that cell?
C# WPF
XAML
I have a grid of 3 rows and 3 columns (9 cells). Each cell has numbers. When I click on one cell, how do I retrieve the numbers in that cell?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raghunath BhukanPosted Mar 17, 2026, 5:57 AM
Hi Clyde Eisenbeis,
In WPF, each
TextBoxalready is the cell holding the number. When you click it, you can directly read its value via itsTextproperty.Simplest approach (handle click / focus)
Attach an event like
GotFocusorPreviewMouseDownto eachTextBox:Use Grid.Row & Grid.Column (no naming hacks)
Let WPF tell you the position directly
XAML
Code-behind
Sam HobbsPosted Mar 17, 2026, 11:28 PM
You have already accepted a a solution therefore I won't get into details but an experienced developer would use a collection, such as a List<> of a class containing three numbers. The window would have a control such as a DataView bound to the collection.