Iterating Controls on Tabstrip

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
Andreas_K
Posts: 9
Joined: Wednesday 13th September 2023 6:04pm
Location: Italy - South Tyrol

Iterating Controls on Tabstrip

Post by Andreas_K »

Hello, i don't know if i make things wrong:
Iconpanel on a Form, Panel on the Iconpanel, then a Tabstrip on the Panel and then Textfields on the Tabstrip. I Iterate over all controls do change the text in the Textbox.
Only visible Tabs will change the Text, all other dont change the Text...
To solve this, i have to insert the textfields in a panel and iterate every control in the panel, inside the Tabs.
(Sorry for my english..)
Thanks
Attachments
Example.tar.gz
(13.12 KiB) Downloaded 162 times
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Iterating Controls on Tabstrip

Post by cogier »

If I understand you correctly, you could give all the TextBoxes the same Action name: -

Image

Then delete all your code and replace with:-

Public Sub Button1_Click()
  
  Action["AllTBs"].Text = "OK"
  
End


Let us know if I have not understood you correctly.
Andreas_K
Posts: 9
Joined: Wednesday 13th September 2023 6:04pm
Location: Italy - South Tyrol

Re: Iterating Controls on Tabstrip

Post by Andreas_K »

Thanks, but this was only a example to show this. I update Database Fields with this system...

Public Sub SaveData(MyObject As Object, sTable As String, sID As String, Optional sSql As String = "")

  Application.Busy = 1

  Dim Res As Result
  Dim ctrl As Control

  If sid <> "" Then
    'Edit
    Try res = db.Edit(sTable, "id ='" & sid & "'")

    For Each ctrl In MyObject.Children

      Select Case Object.Type(ctrl)

        Case "TextBox"
          If ctrl.Tag <> "id"
            res[ctrl.Tag] = TextBox(ctrl).text
          End If
        Case "ComboBox"
          res[ctrl.Tag] = ComboBox(ctrl).text
        Case "ComboSeek"
          res[ctrl.Tag] = ComboSeek(ctrl).text
        Case "CheckBox"
          res[ctrl.Tag] = CheckBox(ctrl).value
        Case "DateBox"
          res[ctrl.tag] = DateBox(ctrl).value
        Case "ValueBox"
          res[ctrl.Tag] = ValueBox(ctrl).value
        Case "TextArea"
          res[ctrl.Tag] = TextArea(ctrl).text
          ' Case "TabStrip"
          '   SaveDataSubdetail(ctrl, ByRef Res)
      End Select

    Next

    'Save
    res.Update

  Else
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Iterating Controls on Tabstrip

Post by BruceSteers »

Try making ctrl an Object not Control with your For loop

I do not know of this TextBox(ctrl).Text syntax you are using?

like this...


  Dim ctrl As Object  ' Use Object here not Control
 
  If sid <> "" Then
    'Edit
    Try res = db.Edit(sTable, "id ='" & sid & "'")
 
    For Each ctrl In MyObject.Children
 
      Select Case Object.Type(ctrl)
 
        Case "TextBox"
          If ctrl.Tag <> "id"
            res[ctrl.Tag] = ctrl.text
          End If
        Case "ComboBox"
          res[ctrl.Tag] = ctrl.text
        Case "ComboSeek"
          res[ctrl.Tag] = ctrl.text
        Case "CheckBox"
          res[ctrl.Tag] = ctrl.value
        Case "DateBox"
          res[ctrl.tag] = ctrl.value
        Case "ValueBox"
          res[ctrl.Tag] = ctrl.value
        Case "TextArea"
          res[ctrl.Tag] = ctrl.text
          ' Case "TabStrip"
          '   SaveDataSubdetail(ctrl, ByRef Res)
      End Select
 
    Next
 




See i use ctrl as Object , this means things like ctrl.Text become usable as Object can be anything and ANY property name can be used and accessed if it exists , but Control.class is limited to only use native Control.class properties that does not have .Text, .Value, etc.
If at first you don't succeed , try doing something differently.
BruceS
Andreas_K
Posts: 9
Joined: Wednesday 13th September 2023 6:04pm
Location: Italy - South Tyrol

Re: Iterating Controls on Tabstrip

Post by Andreas_K »

Thanks, i changed....
Post Reply