[Gambas-user] Enabling multiple TextBoxes with ComboBox

Timothy Marshal-Nichols timothy.marshal-nichols at ...247...
Sun Jun 25 01:36:42 CEST 2006


There are a number of ways you can do this kind of thing.



Option 1: Do it the crude way. This does have the advantage it is very
simple and easy to debug.



    DIM i AS Integer
    i = Val(ComboBox1.Text)
    TextBox1.Enabled = (i >= 1)
    TextBox2.Enabled = (i >= 2)
    TextBox3.Enabled = (i >= 3)
    . ..



Option 2: Set the Tag properties of the TextBox’s to the numbers 1 to 10.
Then Loop through controls the forms controls looking for TextBox’s type of
controls with Tag value set.



    PUBLIC SUB ComboBox1_Click()
      DIM ctrl AS Control
      DIM tb AS TextBox
      DIM i AS Integer
      i = Val(ComboBox1.Text)
      ' Loop through all the controls on the form
      FOR EACH ctrl IN ME.Children
        ' Is this a TextBox
        IF Object.Is(ctrl, "TextBox") THEN
          ' Does the Tag property have a value
          IF ctrl.Tag THEN
             ctrl.Enabled = (Val(ctrl.Tag) <= i)
            Object.SetProperty(ctrl, "Text", 15)
          END IF
        END IF
      NEXT
    END



Option 3:  Use dynamic controls. With this method it could be best to use a
Panel (or ScrollView) to hold the TextBox’s. Then delete all the controls on
the Panel and create the required number of TextBox’s on the Panel. And
resize the Panel. (If space is limited use a ScrollView.)





    PUBLIC SUB ComboBox1_Click()
      DIM ctrl AS Control
      DIM newTextBox AS TextBox
      DIM i AS Integer
      ' Clear current controls from panel
      FOR EACH ctrl IN PanelText.Children
        ctrl.Delete()
      NEXT
      ' Add number of TextBox's to Panel
      FOR i = 1 TO CInt(ComboBox1.Text)
        newTextBox = NEW TextBox(PanelText)
        newTextBox.Text = "15"
        newTextBox.Top = (i - 1) * newTextBox.Height
        ' Make panel fit number of TextBox's
        PanelText.Height = i * newTextBox.Height
      NEXT
    END



Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>

  -----Original Message-----
  From: gambas-user-bounces at lists.sourceforge.net
[mailto:gambas-user-bounces at lists.sourceforge.net]On Behalf Of LinuxSeeker
  Sent: Saturday, 24 June 2006 17:52
  To: Gambas-user at lists.sourceforge.net
  Subject: [Gambas-user] Enabling multiple TextBoxes with ComboBox


  I have a form (form1) with one ComboBox (containing the numbers from 1 to
10) and ten TextBoxes. I want when a user clicks on a number 'N' (where N= a
number contained in the ComboBox) in the textbox the first N TextBoxes in
the form to be activated and have "15" as their content. My code is the
following but it doesn't seem to work:

  PUBLIC SUB ComboBox1_Click()

  DIM i AS Integer
  'disable all
  FOR i = 1 TO 10 STEP 1
  WITH (TextBox\i)
  .enabled=FALSE
  END WITH
  NEXT
  'enable all
  FOR i = 1 TO N STEP 1
  WITH (TextBox\i)
  .enabled=TRUE
  END WITH
  NEXT

  END


  I also tried the following but it failed as well:

  PUBLIC SUB ComboBox1_Click()

  DIM i AS Integer
  'disable all
  FOR i = 1 TO 10 STEP 1
  (TextBox,i).enabled=FALSE
  NEXT
  'enable the first N
  FOR i = 1 TO N STEP 1
  (TextBox,i).enabled=TRUE
  NEXT

  END

  Any suggestions?
  Thanks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20060625/f62c4608/attachment.html>


More information about the User mailing list