Page 1 of 2

Simulating tabs in a form.

PostPosted: Mon Jun 23, 2008 2:50 am
by pitonyak
Is there a good way to simulate "tabs" in a form?

I am looking at a form containing multiple subforms.
The tabs are implemented as pushbuttons.
When a button is pressed, it hides every control on the current form, and displays every control on the form to display.

This is a bit slow, but I was impressed with the results just the same. Anyone think of a better solution?

[Custodis, join the forum and look for the answer here]

Re: Simulating tabs in a form.

PostPosted: Mon Jun 23, 2008 3:35 am
by DrewJensen
Forms are ODF text files, yes?
ODF text files can have sections, yes?
Sections can contain frames, Yes?
Controls can be anchored to frames...yes?
Sections can be hidden - and - unhidden...???

PostPosted: Tue Jun 24, 2008 1:01 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Tue Jun 24, 2008 4:49 pm
by QuazzieEvil
If I may throw in my 2 cents:

Sections are a way to divide a text document (as best I can describe it). to insert a section go to insert | Section and enter a name. see screenshot for sample.

Now, from Basic you can access them from the TextSections property of the form document model. consider the following code listing.

Code: Select all   Expand viewCollapse view
Sub TabControlButtons_OnClick(Event As Object)
   Dim Button As String
   Dim FormDoc As object
   Dim SectionName As String
   Dim CurrState As Boolean
   Button=Event.Source.Model.Label
   FormDoc=Event.Source.Model.Parent.Parent.Parent
   Select Case Button
      Case "Tab 1": SectionName="Section2" REM section 1 is for buttons--start w/ 2
      Case "Tab 2": SectionName="Section3"
      Case "Tab 3": SectionName="Section4"
   End Select
   'GlobalScope.BasicLibraries.LoadLibrary("MRILib")
   'mri FormDoc
   'stop
   CurrState=FormDoc.TextSections.getByName(SectionName).IsVisible
   If CurrState=True Then
      FormDoc.TextSections.getByName(SectionName).IsVisible=False
   Else
      FormDoc.TextSections.getByName(SectionName).IsVisible=True
   End If
End Sub

If you bind this sub to all the tab buttons, it will show/hide the respective section. For a better simulation, you can hide all but the default section when the form loads. Furthermore, the tab handler must make sure to only show one tab at a time. as it is above, it will only show/hide the respective tab, but leave the rest untouched.

That may actually work. I have been trying oh so many other ways but this one. Thanks Drew.

x

PostPosted: Tue Jun 24, 2008 9:03 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Tue Jun 24, 2008 9:34 pm
by DrewJensen
Try putting a frame into the section and dropping onto the frame.

x

PostPosted: Tue Jun 24, 2008 10:06 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Tue Jun 24, 2008 10:22 pm
by QuazzieEvil
it does not really matter where the buttons are. Just make sure you set the correct section names in the select case. in my test, i created four sections. where the first was for the command buttons, and the other three would be for the tab contents. Another options is as follows:

Code: Select all   Expand viewCollapse view
Sub TabControlButtons_OnClick(Event As Object)
   Dim Button As String
   Dim FormDoc As object
   Dim Buttons() As String
   Dim Sections() As String
   Dim NewState As Boolean
   Dim I As Integer
   
   Buttons=Array("Tab 1","Tab 2","Tab 3")
   Sections=Array("Section2","Section3","Section4")
   
   Button=Event.Source.Model.Label
   FormDoc=Event.Source.Model.Parent.Parent.Parent
   For I=0 to UBound(Buttons)
      If Button=Buttons(I) Then
         NewState=True
      Else
         NewState=False
      End If
      FormDoc.TextSections.getByName( Sections(I) ).IsVisible=NewState
   Next I
End Sub

this makes sure that only the section that corresponds to the respective button is visible;

--hope this helps

Re: Simulating tabs in a form.

PostPosted: Tue Jun 24, 2008 10:25 pm
by QuazzieEvil
P.S.

after you run the code and hide the sections, they may remain hidden at design time, which will make it a bit difficult to edit your controls, goto Format | Sections to show the sections again.

PostPosted: Tue Jun 24, 2008 10:48 pm
by Robby
xxx

PostPosted: Tue Jun 24, 2008 11:10 pm
by Robby
xxx

PostPosted: Wed Jun 25, 2008 4:56 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Wed Jun 25, 2008 5:54 pm
by QuazzieEvil
Not sure that this is the problem, but you have ... Button(I) ... rather than Buttons(I) . The array was defined as plural.

Re: Simulating tabs in a form.

PostPosted: Wed Jun 25, 2008 7:37 pm
by DrewJensen
A good time to start using

OPTION EXPLICIT

Add to the top of your module and non declared variables will generate an error - allowing to find that type of mistake quickly...we have been there..

x

PostPosted: Wed Jun 25, 2008 7:43 pm
by Robby
xxx

x

PostPosted: Wed Jun 25, 2008 7:49 pm
by Robby
xxx

PostPosted: Fri Jun 27, 2008 2:47 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Sat Jun 28, 2008 4:19 am
by QuazzieEvil
when you say sub forms, do you mean actual subforms, where a form has another form as parent, rather than the forms collection? or just several forms you added. If you just added several forms, they are not treated as sub forms, but are all top-level forms. Just in case this is the issue, add sub forms by going to the form navigator, right click on the form of choice, and add the new form (sub form). then you can goto the sub form properties and select the master and slave link fields.

as far as the table grid, it does not have table settings as you noted. It gets the table info from its parent form.

PostPosted: Sat Jun 28, 2008 8:15 am
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Sat Jun 28, 2008 8:22 pm
by DrewJensen
Well, I have tried to duplicate your problem both on 2.4.1 and 3.0 beta, but no luck.

Three dataform controls all at the root level of the form, each with a table grid control, 3 sections and 3 buttons to display different sections. It's all working for me.

One thing - I mentioned adding a frame to the sections and anchoring the controls to the frame...bad ideas it seems, that doesn't work at all. Anchoring 'To Character' seems to work the best, for me anyway.

x

PostPosted: Sat Jun 28, 2008 10:17 pm
by Robby
xxx

PostPosted: Sun Jun 29, 2008 8:21 am
by Robby
xxx

x

PostPosted: Mon Jun 30, 2008 9:10 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Mon Jun 30, 2008 11:05 pm
by QuazzieEvil
to use the predefined functions the button must be in the form you are trying to manipulate. Per your structure

Form1 '(on top)
- Navigation controls (pushbuttons: previous, next, save, sort records) + Pushbuttons to control the tabs
Form2
- Table grid
Form3
- Table grid
- SubFormA
-- SubTable grid


are this button you are alking about in form 1 with the tab control buttons? If you want to kep them there, you have to write your own script to move the form to the insert row

exampe:
Code: Select all   Expand viewCollapse view
Sub button_onClick(Event As Object)
REM BOUND TO COMMAND BUTTON IN FORM 1
Dim ThisForm As Object
Dim TargetForm As Object
ThisForm=Event.Source.Model.parent
TargetForm=ThisForm.Parent.getByName("Form2")
TargetForm.moveToInsertRow()

PostPosted: Fri Jul 04, 2008 12:08 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Fri Jul 04, 2008 8:10 pm
by DrewJensen
Why not have a separate data navigator control ( found on the More Controls toolbar ) for each of the dataform controls supplying data to the controls in each section - AND - have the navigation control on the respective section - that way only one navigation control is visible at a time. There is no extra work involved then, beyond adding the new control to each section.

PostPosted: Fri Jul 04, 2008 9:22 pm
by Robby
xxx

Re: Simulating tabs in a form.

PostPosted: Sat Jul 05, 2008 9:11 pm
by Anne
I have been following this discussion, and have implemented tabs in my application. It was working great, but I have just encountered a snag, and was wondering if anyone could help out.
Here is a quick review of what I am trying to do:
Form 1: menu form, containing the tabs that show/hide all other forms
Form 2: input form to allow new entries to a table called Books
Form 3: display form based on a query that involves the Books table, and another table. This form has a subform that uses the Books table to display the detail for the book that is currently selected in the parent data form.

I have implemented the tab simulator basically as described in this post, with each form located within a section of a main document. The tabs show/hide document sections. Here is where I run into a problem: If Form 2 is visible, and I have started to enter data, but not saved it, then I use a tab to switch to form 3, and press a button that performs a RefreshForm function on Form 3, the Auto Primary key field from Form 2 gets displayed right in the middle of Form 3. I think this may be because the subform in form 3 is based on the same table as is Form 2, and somehow in the process of doing a refresh, the database is assigning a value to the primary key of the new record that is open on Form 2, and this causes the field to be updated - the database doesn't know that I currently want that Form 2 to be hidden.

I hope I have made my question clear. If anyone has any ideas on how I could solve this, please let me know. I need to include the primary key field as a field on Form 2, because that number gets used as an ID number for the books, so the user needs to see what number gets assigned to the new record.

Re: Simulating tabs in a form.

PostPosted: Sat Jul 05, 2008 10:12 pm
by QuazzieEvil
hmm, such is the fate of taking the road less traveled--we find ourselves to be lost.

does this only happen when the record is not saved? have you checked your control 'anchor settings' to be the same? I have been making it up as I go along, so will have to try and similate your condition. Does your db have private data? could you post it here, or remove data and post structure.

x

PostPosted: Sat Jul 05, 2008 10:32 pm
by Robby
xxx