Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

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];

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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?

Posted

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?

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...