Simulating tabs in a form.

Creating and using forms
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Simulating tabs in a form.

Post 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]
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Simulating tabs in a form.

Post 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...???
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:51 am, edited 1 time in total.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post 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

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.
Attachments
Form Tab Simulation1.png
Form Tab Simulation1.png (11.52 KiB) Viewed 29723 times
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:52 am, edited 1 time in total.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Simulating tabs in a form.

Post by DrewJensen »

Try putting a frame into the section and dropping onto the frame.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:52 am, edited 1 time in total.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post 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

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
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post 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.
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:52 am, edited 1 time in total.
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:53 am, edited 1 time in total.
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:55 am, edited 1 time in total.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post by QuazzieEvil »

Not sure that this is the problem, but you have ... Button(I) ... rather than Buttons(I) . The array was defined as plural.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Simulating tabs in a form.

Post 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..
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:55 am, edited 1 time in total.
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:56 am, edited 1 time in total.
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:56 am, edited 1 time in total.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post 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.
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:56 am, edited 2 times in total.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Simulating tabs in a form.

Post 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.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:57 am, edited 1 time in total.
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:57 am, edited 1 time in total.
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:57 am, edited 1 time in total.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post 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

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()
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:58 am, edited 1 time in total.
User avatar
DrewJensen
Volunteer
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Re: Simulating tabs in a form.

Post 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.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
Robby

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:58 am, edited 1 time in total.
Anne
Posts: 25
Joined: Fri Feb 01, 2008 2:22 am

Re: Simulating tabs in a form.

Post 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.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Post 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.
Robby

x

Post by Robby »

xxx
Last edited by Robby on Sun Dec 11, 2011 9:58 am, edited 1 time in total.
Post Reply