Page 1 of 1

Iterating Controls on Tabstrip

Posted: Sunday 31st December 2023 8:44am
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

Re: Iterating Controls on Tabstrip

Posted: Sunday 31st December 2023 10:48am
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.

Re: Iterating Controls on Tabstrip

Posted: Sunday 31st December 2023 1:02pm
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

Re: Iterating Controls on Tabstrip

Posted: Sunday 31st December 2023 2:00pm
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.

Re: Iterating Controls on Tabstrip

Posted: Monday 1st January 2024 3:57pm
by Andreas_K
Thanks, i changed....