Ice725 Posted April 26, 2004 Posted April 26, 2004 Can't seem to get this to work: TextBox[][] txtGames = new TextBox[3][5]; Is it possible to do multidimensional arrays with TextBoxes? Quote
*Experts* Bucky Posted April 26, 2004 *Experts* Posted April 26, 2004 Using [][] does not define a multidimensional array; it defines a jagged array. Perhaps the syntax you're looking for is: TextBox[,] txtGames = new TextBox[3,5]; Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Ice725 Posted April 26, 2004 Author Posted April 26, 2004 Is there an easy way to add a TextChanged Event for all the first dimension in the array? For instance, I'd like to update lblSeries[0] by adding the following at runtime: txtGames[0,0] txtGames[0,1] txtGames[0,2] same with lblSeries[1], would be updated when any of the following text values are changed: txtGames[1,0] txtGames[1,1] txtGames[1,2] Any ideas? Quote
*Experts* mutant Posted April 26, 2004 *Experts* Posted April 26, 2004 Use a for loop and add the handler in it. Quote
Ice725 Posted April 26, 2004 Author Posted April 26, 2004 Never hard-coded handlers before. I tried this, but it gives me an error saying I'm missing a ' ) expected for (int x = 0; x < 3; x++) this.txtGame[x,0].Leave += new System.EventHandler(this.txtGame[x,0]_Leave); How should my Method look? Quote
*Experts* Bucky Posted April 27, 2004 *Experts* Posted April 27, 2004 You can't change the name of all the event handlers you're adding; they have to all be the same method. This is okay, because you can discern between which TextBox is firing the event by casting the sender object to a TextBox and retrieving its name. So, here's what your loop should look like: for (int x = 0; x < 3; x++) this.txtGame[x,0].Leave += new System.EventHandler(this.txtGame_Leave); And here's your event handler: private void txtGame_Leave(object sender, EventArgs e) { TextBox txt = (TextBox)sender; // Now just check the value of txt.Name to determine which textbox fired the event } You could consider setting each TextBox's Tag property to reflect the index of that TextBox within the array; that way, in the event handler, you can just retrieve the Tag to figure out which TextBox activated the event. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.