Page 1 of 1

A Question about (FiveLinux) Class TWBrowse

PostPosted: Fri Sep 05, 2008 8:32 am
by xProgrammer
Hi Antonio

I don't quite know how to do something. Take a TWBrowse. I want to be able to set the default selection to some position other than 1. I can do this by setting oBrw:nAt but the issue is if I set that to record n then records 1 through n-1 aren't displayed. Is there a way around this? To date I have been skirting the issue by re-ordering the arrays that are browsed so the record I want selected as default is in position 1, but I am coming to situations where this is less than desirable. Can you advise?

You can see the issue using the testbrwa.prg program you sent me with the addition of 1 line as follows:

Code: Select all  Expand view
// Using a browse to display a multidimensional array

#include "FiveLinux.ch"

function Main()

   local oWnd, oBrw, aTest := { { "one", "two" }, { "three", "four" } }

   DEFINE WINDOW oWnd TITLE "Testing Browses" SIZE 522, 317

   @ 2, 2 BROWSE oBrw OF oWnd ;
      HEADERS "First", "Second" ;
      FIELDS  aTest[ oBrw:nAt ][ 1 ], aTest[ oBrw:nAt ][ 2 ]

   oBrw:SetArray( aTest )
   oBrw:nAt := 2              // this is the line I added to set record 2 as the "default" choice.

   @ 28, 2 BUTTON "_Ok" OF oWnd ACTION oWnd:End()
   
   @ 28, 30 BUTTON "Add" OF oWnd ACTION ( AAdd( aTest, { "five", "six" } ), oBrw:SetArray( aTest ), oBrw:GoTop() )

   ACTIVATE WINDOW oWnd

return nil


I note that in TDialog there is an intriguing piece of code to do with TListbox objects, namely:

Code: Select all  Expand view
   // Listbox controls initialization workaround
   for n = 1 to Len( ::aControls )
      if ::aControls[ n ]:ClassName() == "TLISTBOX"
         ::aControls[ n ]:SelItem( ::aControls[ n ]:nAt )
      endif
   next


Is this to overcome a comparable issue with list boxes? Is there a way of having an equivalent to SelItem() in TWBrowse?

Regards
Doug
(xProgrammer)

PostPosted: Mon Sep 08, 2008 11:23 am
by Antonio Linares
Doug,

Please try this workaround:

oBrw:SetArray( aTest )
oBrw:GoDown()

or for n rows:
Code: Select all  Expand view
for n = 1 to nRows
   oBrw:GoDown()
next

PostPosted: Mon Sep 08, 2008 11:57 am
by xProgrammer
Hi Antonio

I think I had already tried this "trick" but it doesn't work because the n-th row is put at the top of the browse and the rows above aren't visible. (Unless you arrow up to them which is no good and moves the default selection you have just set.)

Here is the example:

Code: Select all  Expand view
// Using a browse to display a multidimensional array

#include "FiveLinux.ch"

function Main()

   local oWnd, oBrw, aTest := { { "one", "two" }, { "three", "four" } }

   DEFINE WINDOW oWnd TITLE "Testing Browses" SIZE 522, 317

   @ 2, 2 BROWSE oBrw OF oWnd ;
      HEADERS "First", "Second" ;
      FIELDS  aTest[ oBrw:nAt ][ 1 ], aTest[ oBrw:nAt ][ 2 ]

   oBrw:SetArray( aTest )
   //oBrw:nAt := 2
   oBrw:GoDown()

   @ 28, 2 BUTTON "_Ok" OF oWnd ACTION oWnd:End()
   
   @ 28, 30 BUTTON "Add" OF oWnd ACTION ( AAdd( aTest, { "five", "six" } ), oBrw:SetArray( aTest ), oBrw:GoTop() )

   ACTIVATE WINDOW oWnd

return nil


Regards
Doug

PostPosted: Mon Sep 08, 2008 2:01 pm
by Antonio Linares
Doug,

This is not working totally right yet, but we are closer :-)

oBrw:SetArray( aTest )
oBrw:nRowPos = 2

PostPosted: Mon Sep 08, 2008 2:16 pm
by Antonio Linares
No, it is not a right solution as oBrw:nAt is not properly set :-(

PostPosted: Mon Sep 08, 2008 2:33 pm
by Antonio Linares
This is better:

oBrw:SetArray( aTest )
oBrw:nAt = 2
oBrw:nRowPos = 2