Iterate through views and change properties

harlechguy

Member
Licensed User
Longtime User
Hi, am new to this - be gentle!

I have five edittext boxes on a form - at various points of data entry I wish to un-enable 5 of them.

I have given them numeric 'tags' and would like to unenable numbers 2 - 6

e.g something like

for i = 2 to 6

if edittext.tag = i then
edittext.enable = false
end if
next

strikes me as something that should be very simple?

many thanks
 

klaus

Expert
Licensed User
Longtime User
You have two possibilities:
- Use an Array of Views
- Put the EditText views on a Panel and use Panel1.GetView(i)

Attached a small example showing both possibilities.

Best regards.
 

Attachments

  • ViewsArray.zip
    6.7 KB · Views: 267
Upvote 0

harlechguy

Member
Licensed User
Longtime User
Thanks Erel, thanks Klaus

understand all the solutions - except - using a panel how do you know which 'view' is which in the panel array?

e.g

edt = Panel1.GetView(0) is the first 'edittext' view but where is this set?

thanks again
 
Upvote 0

harlechguy

Member
Licensed User
Longtime User
In Klaus' example

edt = Panel1.GetView(0) has a tag of '5' and I cannot see a reference to the tag property

am I looking in the right place?

thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You don't need to.
In Panel1 panel there are 4 EditText views and their index begins with 0 and is incremented by one when adding the next one.
This means that
EditText5 = index 0
EditText6 = index 1
EditText7 = index 2
EditText8 = index 3
so no need for the Tag property.

But in the event routine, which is in the example the same for all EditText views, we need the Tag property to know what EditText view raised the event.

Hope this is clear enough.

Best regards.
 
Upvote 0

harlechguy

Member
Licensed User
Longtime User
Thanks - makes sense, just need to note the order that controls are added to a panel - or 'tag' them for future reference perhaps

thanks again
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The advantage when you control the adding order is that with the index you directly know what view you are looking for, avoiding to go, in a loop, through all the views and check the Tag property to check the good one.
If you want to manage different sets of views, put each set on a seperate panel and then it's quite easy to manage them.

Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…