| Home | Previous Lesson: Programming Tab control Next Lesson: Using Independent Controls For Each Tab Page |
You may come across a situation where you want to use a single control say a DataWindow control for all tab pages and want to filter that DataWindow depending on the tab page selection. For example, say you want to create a tab control with three tab pages, Receipts, Issues, Returns. You may want to use a single DataWindow control and retrieve all the transactions and filter transactions depending on the selected tab page.
What you could do in this situation is you can place a tab control on the window. Place a DataWindow control somewhere on the window (make sure you don't place the DataWindow control directly over the tab control). Then either you can pull the DataWindow control onto the tab control and set 'BringToTop' option from it's popup menu or you can do that at run-time through programming.
The above sequence is very important. If you want to refer to the DataWindow dw_1 from window's open event, you can refer as:
dw_1.SetTransObject( SQLCA )
The thumb rule you need to understand here is that, if you place a control on a tab page directly that control becomes part of that tab page. For ex, if you place dw_1 on the Receipts tab page directly and want to set it's transaction object in the window's open event, you need to code like:
tab_1.tabpage_receipts.dw_1.SetTransObject( SQLCA )
The above reference to the DataWindow is similar to referring to an object in a custom user object. You can refer to the DataWindow directly from tabpage_receipts tab page, but not from other tab pages. For example,
dw_1.SetTransObject( SQLCA )
The above statement is valid if you are writing in any event for the tab page 'tabpage_receipts'. However, if you write the same code in 'tabpage_issues', you get compilation error.
Insert two tab pages in the tab control as shown in the above picture (One tab page is created by default for you). Specify 'R', 'I' and 'T' as tag values respectively. We will be using these tag values as the retrieval arguments for the DataWindow to retrieve transactions from the database. Write the following code in the SelectionChanged event of the tab control 'tab_1'.
String ls_TranType
ls_TranType = This.Control[ NewIndex ].Tag
Parent.Trigger Event ue_filter_trans( ls_TranType )
The index of the selected tab page is passed as an argument to the SelectionChanged event. Using that index number, we are reading the tag value of the selected tab page and passing that to the event 'ue_filter_trans' as an argument. When you compile the code you get error since 'ue_filter_trans' event is not yet defined. Just comment the last line and define 'ue_filter_trans' event at the window level. Define a string argument 'as_tran_type'. Now, uncomment the last line and compile it.
As you may recall, window has an array property named 'Control'. All the controls that you place on the window is listed in this property. Similarly, tab control also has 'control' property. It contains all the tab pages that you paint at design time. You can observe in the second line we are referring to 'control' property.
dw_trans.SetFilter( "tran_type = " + '"' + upper( &
as_tran_type ) + '"' )
dw_trans.Filter()
Return (dw_trans.RowCount() - dw_trans.FilteredCount())
Write the above code to the 'ue_filter_trans' event. I am sure you know what the above code does. In the window opening event, make sure to set the transaction object to the DataWindow control dw_1 and retrieve the data into it.
Save this window as 'w_tab_demo1' and open this window after the w_login window in the application's open event and run the application or download the application by clicking on the button and see it in action. If you are not downloading code, then don't forget creating a DataWindow for the trans table and assigning that DataWindow object to the DataWindow control before you run the application.
| Home | Previous Lesson: Programming Tab control Next Lesson: Using Independent Controls For Each Tab Page |