enter image description here

I make a program for solving Sudoku for educational purposes, the question arose whether it is possible to dynamically access these textboxes in order to read the values ​​from textboxes and throw them into an array? About datagrid vkurse, just IMHO option using textboxes is better ..

string k = "textbox",temp; int l=1; int[][] myarr; for (int i=0;i<9;i++) for (int j=0;j<9;i++) { temp = k + l.Tostring(); myarray[i][j] = temp.value(); l++; } 

I ask you not to throw tomatoes, I understand what kind of nonsense I wrote in the code, the options themselves are just as interesting as possible? Even the question correctly in Google could not come up ..

    2 answers 2

    Welcome to StackOverflow.

     string boxId = k + l.Tostring(); // или k + "_" + i.ToString() + "_" + j.ToString(); // panel - контрол, на котором находятся все TextBox-ы TextBox box = panel.FindControl(boxId) as TextBox; int value; if (box != null && int.TryParse(box.Text, out value)) { // ... } 

      In general, this kind of decision came out, leaving, suddenly to whom it will come in handy

        int[,] myarr = new int [9,9]; int l = 1, value; string k = "textbox", boxId; TextBox box; for(int i = 0; i<9;i++) for(int j = 0; j<9;j++) { boxId = k + l.ToString(); l++; box = this.Controls.Find(boxId, true).FirstOrDefault() as TextBox; if (box != null && int.TryParse(box.Text, out value)) { myarr[i, j] = int.Parse(box.Text); } }