ToniMontana Posted March 19, 2004 Posted March 19, 2004 Hi all, I want to change a set of similar controls in a form. How can I create a reference (like a C-pointer) to switch from one control to the next? Or do I have to organize them as a control-array? How can I do that, what is the best way? Quote Greetings, Toni.
CattleRustler Posted March 19, 2004 Posted March 19, 2004 you may want to use For-Each loop, with a looper object of the same type Dim oTB as textbox For Each otb in <wherever> ...do something with oTB.~~~ Next Quote mod2software Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
ToniMontana Posted March 19, 2004 Author Posted March 19, 2004 Hi, thank you for the reply, but this will not solve the problem. Imagine you have many different controls in a form and some textBoxes too, lets say 10. And let us assume that 5 of these textBoxes belog to a group and only these 5 must be changed in a particular way. How can I do this without having to write: switch(textboxName) { case "T1": t1.Text = "Hello"; break; .... } How can I do that with a textBox-Array?? I really dont know, I am a noob... I know from VB that it creates an array if you copy&paste a control. Is this the same in Visual-Studio for C# ? Quote Greetings, Toni.
Administrators PlausiblyDamp Posted March 19, 2004 Administrators Posted March 19, 2004 Would the 5 that need to be changed be physically close to each other on the form? If so you could put them in a panel and do a for ... each over the panels controls. Although the designer doesn't support the creation of control ararys like VB6 did you can still create the arrays in code yourself... Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mocella Posted March 22, 2004 Posted March 22, 2004 Like PlausiblyDamp said, just create your own array of TextBoxes and add the appropriate members. It should look something like this Dim boxArray(4) as textbox boxArray(0) = someTextBoxControlInstance ... boxArray(4) = anotherTextBoxControlInstance Dim oTB as textbox For Each otb in boxArray ...do something with oTB.~~~ Next Quote
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.