Click to See Complete Forum and Search --> : Index
simon ong
Nov 29th, 2007, 12:31 AM
hi:
What Is the Equivalent of index as in vb6 to C#?
say I have 55 Textboxes, I need to place 50 data in only 50 textboxes, the remaining 5 are for other usage. How can I approach this ?
(It is easy using index in VB6)
Thanks
jmcilhinney
Nov 29th, 2007, 02:09 AM
The design time support for control arrays doesn't exist in C# or VB.NET because it isn't needed. If you want to access objects by index then create an array and assign those objects to the elements. If those objects are TextBoxes then they still get treated the same way. An array is an array regardless.
simon ong
Nov 30th, 2007, 11:16 AM
Any chance you can show me how to do this?
Thanks
Atheist
Nov 30th, 2007, 11:27 AM
TextBox[] textBoxArray = new TextBox[2];
private void Form1_Load(object sender, EventArgs e)
{
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
}
simon ong
Dec 1st, 2007, 09:27 AM
TextBox[] textBoxArray = new TextBox[2];
private void Form1_Load(object sender, EventArgs e)
{
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
}
There are errors:
"Error 3 Preprocessor directives must appear as the first non-whitespace character on a line"
:confused:
penagate
Dec 1st, 2007, 10:02 AM
Sorry about that. It's a bug in the forum software which hasn't been fixed yet.
Here's what the code should look like:
TextBox[] textBoxArray = new TextBox[2];
private void Form1_Load(object sender, EventArgs e)
{
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
}
Paul M
Dec 2nd, 2007, 05:18 PM
I don't know but wouldn't it be better to add...
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
in the InitializeComponent event instead?
jmcilhinney
Dec 2nd, 2007, 05:28 PM
I don't know but wouldn't it be better to add...
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
in the InitializeComponent event instead?There is no InitializeComponent event. InitializeComponent is a method and it's generated by the IDE. You should not be editing any code in that method except in direst need. You can add code to a constructor, AFTER the call to InitializeComponent. That would be just as legitimate as adding it to the Load event handler but it really would offer no advantage. The only way that could be better is if you were going to try to access that array's elements before calling Show or ShowDialog on the form, and I can't think of a legitimate reason for that.
Paul M
Dec 2nd, 2007, 05:31 PM
It is the Class Constructor though, no?
Thats why i assumed it would be best to do it there.
penagate
Dec 2nd, 2007, 08:06 PM
It is the Class Constructor though, no?
No. The constructor is the constructor.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.