0

So I'm trying to create an 8X8 grid of textboxes. I want to have the ability to also access the textboxes when I need to search through them. I have looked into considering an embedded List (i.e. List<List<TextBoxes>>) Where the inner list has 8 slots and the outer lists also has 8. I was wondering if there was an easier way.

Also how would I add my textboxes from my form into this 2d array?

Thanks for the help.

-Lewis

3 Answers 3

2

You could use a TextBox[,] for this purpose:

private TextBox[,] textboxes;

public YourClass() {
    // Add this after the text boxes have actually been set up...

    textboxes = new TextBox[,] {
        {textbox00, textbox01, textbox02, ...},
        {textbox10, textbox11, textbox12, ...},
        ,,,
    };
}

Then you can access textbox00 as textboxes[0,0], textbox56 as textboxes[5,6], etc.

Sign up to request clarification or add additional context in comments.

Comments

0

try this:

private class Position
{
    internal int Row;
    internal int Col;
}

var txtBoxesDict=new Dictionary<Position, TextBox>();

txtBoxesDict.Add(new Position{Row=0,Col=0},txtBox0);

To access thrid textbox in fourth row, you can use:

MessageBox.Show(txtBoxesDict[new Position{Row=3, Col=2}].Text);

Comments

0

Use a standard 2D array TextBoxes[8,8]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.