Simulating tabs in a form.

Creating and using forms

Simulating tabs in a form.

Postby pitonyak » Mon Jun 23, 2008 2:50 am

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
pitonyak
 
Posts: 185
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: Simulating tabs in a form.

Postby DrewJensen » Mon Jun 23, 2008 3:35 am

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...???
The Document Foundation member
Apache OpenOffice Incubator podling PPMC member
LibreOffice & OpenOffice.org on Ubuntu 11.04 + Windows XP - 7
User avatar
DrewJensen
 
Posts: 1733
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Postby Robby » Tue Jun 24, 2008 1:01 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:51 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby QuazzieEvil » Tue Jun 24, 2008 4:49 pm

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.
Attachments
Form Tab Simulation1.png
Form Tab Simulation1.png (11.52 KiB) Viewed 18004 times
QuazzieEvil
Volunteer
 
Posts: 282
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

x

Postby Robby » Tue Jun 24, 2008 9:03 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:52 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby DrewJensen » Tue Jun 24, 2008 9:34 pm

Try putting a frame into the section and dropping onto the frame.
The Document Foundation member
Apache OpenOffice Incubator podling PPMC member
LibreOffice & OpenOffice.org on Ubuntu 11.04 + Windows XP - 7
User avatar
DrewJensen
 
Posts: 1733
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

x

Postby Robby » Tue Jun 24, 2008 10:06 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:52 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby QuazzieEvil » Tue Jun 24, 2008 10:22 pm

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

Re: Simulating tabs in a form.

Postby QuazzieEvil » Tue Jun 24, 2008 10:25 pm

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

Postby Robby » Tue Jun 24, 2008 10:48 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:52 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Postby Robby » Tue Jun 24, 2008 11:10 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:53 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Postby Robby » Wed Jun 25, 2008 4:56 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:55 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby QuazzieEvil » Wed Jun 25, 2008 5:54 pm

Not sure that this is the problem, but you have ... Button(I) ... rather than Buttons(I) . The array was defined as plural.
QuazzieEvil
Volunteer
 
Posts: 282
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: Simulating tabs in a form.

Postby DrewJensen » Wed Jun 25, 2008 7:37 pm

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..
The Document Foundation member
Apache OpenOffice Incubator podling PPMC member
LibreOffice & OpenOffice.org on Ubuntu 11.04 + Windows XP - 7
User avatar
DrewJensen
 
Posts: 1733
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

x

Postby Robby » Wed Jun 25, 2008 7:43 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:55 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

x

Postby Robby » Wed Jun 25, 2008 7:49 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:56 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Postby Robby » Fri Jun 27, 2008 2:47 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:56 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby QuazzieEvil » Sat Jun 28, 2008 4:19 am

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

Postby Robby » Sat Jun 28, 2008 8:15 am

xxx
Last edited by Robby on Sun Dec 11, 2011 9:56 am, edited 2 times in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby DrewJensen » Sat Jun 28, 2008 8:22 pm

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.
The Document Foundation member
Apache OpenOffice Incubator podling PPMC member
LibreOffice & OpenOffice.org on Ubuntu 11.04 + Windows XP - 7
User avatar
DrewJensen
 
Posts: 1733
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

x

Postby Robby » Sat Jun 28, 2008 10:17 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:57 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Postby Robby » Sun Jun 29, 2008 8:21 am

xxx
Last edited by Robby on Sun Dec 11, 2011 9:57 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

x

Postby Robby » Mon Jun 30, 2008 9:10 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:57 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby QuazzieEvil » Mon Jun 30, 2008 11:05 pm

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

Postby Robby » Fri Jul 04, 2008 12:08 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:58 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby DrewJensen » Fri Jul 04, 2008 8:10 pm

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.
The Document Foundation member
Apache OpenOffice Incubator podling PPMC member
LibreOffice & OpenOffice.org on Ubuntu 11.04 + Windows XP - 7
User avatar
DrewJensen
 
Posts: 1733
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Postby Robby » Fri Jul 04, 2008 9:22 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:58 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Re: Simulating tabs in a form.

Postby Anne » Sat Jul 05, 2008 9:11 pm

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.
Anne
 
Posts: 25
Joined: Fri Feb 01, 2008 2:22 am

Re: Simulating tabs in a form.

Postby QuazzieEvil » Sat Jul 05, 2008 10:12 pm

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

x

Postby Robby » Sat Jul 05, 2008 10:32 pm

xxx
Last edited by Robby on Sun Dec 11, 2011 9:58 am, edited 1 time in total.
User avatar
Robby
Banned
 
Posts: 54
Joined: Tue Jun 24, 2008 12:39 pm

Next

Return to Forms

Who is online

Users browsing this forum: No registered users and 6 guests