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
Printable View
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
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.
Any chance you can show me how to do this?
Thanks
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:Quote:
Originally Posted by Atheist
"Error 3 Preprocessor directives must appear as the first non-whitespace character on a line"
:confused:
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:
Quote:
Originally Posted by Atheist
I don't know but wouldn't it be better to add...
in the InitializeComponent event instead?Code:textBoxArray[0] = textBox1;
textBoxArray[1] = textBox2;
textBoxArray[2] = textBox3;
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.Quote:
Originally Posted by Paul M
It is the Class Constructor though, no?
Thats why i assumed it would be best to do it there.
No. The constructor is the constructor.Quote:
Originally Posted by Paul M