none
how to name objects (for example label, combobox, textbox) using one name but with different index RRS feed

  • Question

  • Hi List,

    I am trying to name lets say 20 labels, textboxes, and comboboxes somehow to use them problematically. One way to do is to use index, that is what I used to do in VB6.

    for example:

    mytextbox(1), mytextbox(2),mytextbox(3),....

    mycombo(1),mycombo(2),mycombo(3),.....

    Any idea how I can do this in c#?

    thanks,

    Arvin

    Monday, July 9, 2012 8:29 PM

Answers

  • You can do it like this - Create Labels label1, label2, label3.. label20. Then create an array of Labels as belwo,

    label[] myLabel = { label1, label2, ..., label20 };

    Then you can access the labels in the same way you used to do it in VB6 as myLabel[0], myLabel[1]  etc.

    Similarly you can do it for TextBox and ComboBoxes.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, July 10, 2012 5:40 AM
  • I think this article can help you out.

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Tuesday, July 10, 2012 5:41 AM

All replies

  • You can do it like this - Create Labels label1, label2, label3.. label20. Then create an array of Labels as belwo,

    label[] myLabel = { label1, label2, ..., label20 };

    Then you can access the labels in the same way you used to do it in VB6 as myLabel[0], myLabel[1]  etc.

    Similarly you can do it for TextBox and ComboBoxes.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, July 10, 2012 5:40 AM
  • I think this article can help you out.

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Tuesday, July 10, 2012 5:41 AM