|
-
Nov 29th, 2007, 01:31 AM
#1
Thread Starter
Addicted Member
Index
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
-
Nov 29th, 2007, 03:09 AM
#2
Re: Index
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.
-
Nov 30th, 2007, 12:16 PM
#3
Thread Starter
Addicted Member
Re: Index
Any chance you can show me how to do this?
Thanks
-
Nov 30th, 2007, 12:27 PM
#4
Re: Index
C# Code:
TextBox[] textBoxArray = new TextBox[2];
private void Form1_Load(object sender, EventArgs e)
{
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
}
-
Dec 1st, 2007, 10:27 AM
#5
Thread Starter
Addicted Member
Re: Index
 Originally Posted by Atheist
C# Code:
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"
-
Dec 1st, 2007, 11:02 AM
#6
Re: Index
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:
 Originally Posted by Atheist
Code:
TextBox[] textBoxArray = new TextBox[2];
private void Form1_Load(object sender, EventArgs e)
{
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
}
-
Dec 2nd, 2007, 06:18 PM
#7
Re: Index
I don't know but wouldn't it be better to add...
Code:
textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
in the InitializeComponent event instead?
-
Dec 2nd, 2007, 06:28 PM
#8
Re: Index
 Originally Posted by Paul M
I don't know but wouldn't it be better to add...
Code:
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.
-
Dec 2nd, 2007, 06:31 PM
#9
Re: Index
It is the Class Constructor though, no?
Thats why i assumed it would be best to do it there.
-
Dec 2nd, 2007, 09:06 PM
#10
Re: Index
 Originally Posted by Paul M
It is the Class Constructor though, no?
No. The constructor is the constructor.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|