Hi Guys,
I'm making a program ( game sudoku) in C# - windows application which contains many textboxes (81) labeled as shown below.
String[] polja = { "tbA11", "tbA12", "tbA13", "tbA21", "tbA22", "tbA23", "tbA31", "tbA32", "tbA33","tbB11", "tbB12", "tbB13", "tbB21", "tbB22", "tbB23", "tbB31", "tbB32", "tbB33",...
... "tbI11", "tbI12", "tbI13", "tbI21", "tbI22", "tbI23", "tbI31", "tbI32", "tbI33" };
when i click on button "START", i'd like to fill some of that textboxes (25) with a random generated numbers 1-9 (int s). I was also created another random function for generate numbers 0-80 (int pol), which present indexes of string[] polja ....so far so good.
My problem is on the next step.
I need to convert string from polja ("tb..." ) to textbox with same name - e.q. tbA11.Text = s.ToString //for writting numbers 1-9 (int s) into.
(FindControl function doesn't work in my case)
my code.....
private void btn_start_Click(object sender, EventArgs e) {
NapolniPolje();
}
void NapolniPolje() {
for (int i = 0; i < 25; i++
{
int pol = new Random().Next(80); // for index 0-80
tbPolje.Text = pol.ToString(); //textbox for test only
int s = new Random().Next(9) + 1; //for numbers 1-9
tbRezultat.Text = s.ToString(); //textbox for test only
string txt = polja[pol]; //txt = "tb..."
Object obj1 = new Object();
obj1 = ((Object)txt);
TextBox tb = new TextBox();
tb =obj1 as TextBox ;
tbpolje1.Text = txt; //textbox for test only
tb.Text = s.ToString();
}
}
any ideas...
Regards
Bojan