Group disparate XAML textboxes into an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vandtekor
    New Member
    • Dec 2009
    • 2

    #1

    Group disparate XAML textboxes into an array

    Hi,

    I am new to C#, and writing a sudoku solver as a WPF application. I've declared the windows contents as 81 textboxes in a series of grids, a label and a button. A click to the "solve" button triggers an event handler that I want to iterate over the given textboxes, and load their Text attribute into a 2d array of 2d arrays. For this I need to be able to enumerate the textboxes declared in the XAML.

    I can access one textbox easily enough in the C#, but how do I get all 81 of them? If I were using a higher level language, I would use eval() with a constant string and a counter, but I gather C# being compiled has no eval.

    Any help would be appreciated on this please.

    Thanks!
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Maybe you should just add the textboxes to a textbox[] at the time you make them (assuming they are being made programmaticall y and not in design time.

    Or... A 'for loop', looking at the .Controls of the form, checking if the type is TextBox

    Comment

    • vandtekor
      New Member
      • Dec 2009
      • 2

      #3
      Creating the textboxes in code rather than XAML had not really occurred to me, but I have now changed it over, so I have an array of TextBox objects that I can access.

      Thanks for your help!

      Comment

      Working...