C# WPF
XAML
Code
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raghunath BhukanRank #744 · 3.1K reputationPosted Mar 17, 2026, 1:57 AM EDT
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 HobbsRank #107 · 20.5K reputationPosted Mar 17, 2026, 7:28 PM EDT
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.