DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Sudoku (http://www.daniweb.com/forums/thread193050.html)

bokr66 May 20th, 2009 7:55 pm
Sudoku
 
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

ddanbe May 21st, 2009 6:25 am
Re: Sudoku
 
This thread already is about what you want I think.
http://www.daniweb.com/forums/thread180533.html


All times are GMT -4. The time now is 11:50 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC