Now a difficult one...

Discussion in 'Questions (Windows Mobile)' started by Cableguy, Jun 30, 2007.

  1. Cableguy

    Cableguy Expert Licensed User

    How can we change a controls name in runtime??


    I a have a set of textboxs that are created by the press of a button, and also can be deleted by the press of a button, and are turned on/off (visible), by the selection on a combobox...

    Since deleting an item in a combobox automaticaly resizes it, I need to re-associate the correct textbox to the correct combobox item...

    like this


    item0 is associated with textbox1
    item1 is associated with textbox2
    item2 is associated with textbox3
    item3 is associated with textbox4

    if i remove item 1 and therefore remove textbox2

    item2 automatically becomes item2 so i need to re-name textbox3 to textbox2
    and textbox4 to textbox3


    HOW????
    It doesnt seem to be possible to rename the controls...
     
  2. Zemog

    Zemog Member

    I'm not really sure to have understood what you're trying to do, but I would try to keep a content-name relation instead of name-name.

    if I do something like
    MyComboBox.add("apple")
    and then create a textbox called MyTextBox3
    then the relation would be "apple,3" stored on a table row, therefore, when the item "apple" gets deleted or selected, I would know the related textbox

    hehe, I might as well be very off base here :eek:

    how are you currently keeping the relations?
     
  3. Cableguy

    Cableguy Expert Licensed User

    I am using the combobox index to textbox(combobox.index+1) relation
     
  4. Zemog

    Zemog Member

    hmmm I have another idea, keep the textbox relation inside an arraylist, then when you remove the combobox item then remove the arraylist item and you´ll keep the relations in sync

    Being TextBoxes an arraylist:

    TextBoxes.RemoveAt(MyComboBox.SelectedIndex)

    And use TextBoxes.item(MyComboBox.SelectedIndex) to refer to the textbox, even better would be to use a sub to return the name
     
  5. Cableguy

    Cableguy Expert Licensed User

    I like it, i'll play with it and see if I can make it work the way I want...

    Thanks
     
  6. Zemog

    Zemog Member

    I'm sure that by now you have solved the problem. But I still wanted to give it a try, so I've attached a sample in case someone else needs it.

    The code has no comments at all, it is very short and should be self explanatory, I got lazy :sign0013:

    And as some books say, the task of relocating the edit boxes is left to reader as an exercise ;)
     

    Attached Files:

  7. Cableguy

    Cableguy Expert Licensed User

    Very nice, I'll only have the time this afternoon...
    I'll post some after thougths...
     
Loading...