Advice needed about XBrowse usage!

Advice needed about XBrowse usage!

Postby Horizon » Wed Aug 26, 2009 2:10 pm

Hi,

I have two files. KART.dbf and NAMES.dbf (DBFCDX). Every record in KART.dbf has more than one records in NAMES.dbf (1 to N). All of fields is indexed. I run the test1.exe. I can switch the sort order by clicking the headers of first 3 columns. I can not sort 4th column, because its relation field. When I click the header of 4th column, I want to change the XBrowse contents and change the relation file another like view in test2.exe.

How Can I change it in test1.prg like view in test2.prg?

KART.dbf
-------------------
id, Nümeric, AutoID (created by me)
Ref1, Character
Ref2, Character
It has also indexes TAGs called ID, REF1, REF2

NAMES.dbf
--------------------
id, Nümeric, AutoID (created by me)
Kid, Nümeric (Relation field to KART.dbf. It includes id in KART.dbf)
Name, Character
It has also indexes TAGs called ID, KID, NAME

KART.dbf includes data
----------------------------
1, "Ref11", "Ref12"
2, "Ref21", "Ref22"
3, "Ref31", "Ref32"
4, "Ref41", "Ref42"

NAMES.dbf includes data
----------------------------
1, 1, "Albert"
2, 1, "John"
3, 2, "Hakan"
4, 2, "Smith"
5, 1, "Antonio"
6, 1, "Luiz"
7, 3, "Tommy"
8, 3, "Dave"

Image
test1.prg
Code: Select all  Expand view
#include "FiveWin.ch"
#include "XBrowse.Ch"
REQUEST DBFCDX
PROCEDURE MAIN()

   RDDSetDefault( 'DBFCDX' )


        USE NAMES NEW EXCLUSIVE
        INDEX ON ID TAG ID
        INDEX ON KID TAG KID
    INDEX ON NAME TAG NAME
    SET ORDER TO TAG KID

    USE KART NEW EXCLUSIVE
        INDEX ON ID TAG ID
        INDEX ON REF1 TAG REF1
    INDEX ON REF2 TAG REF2
    SET ORDER TO TAG ID
    SET RELATION TO ID INTO NAMES
    GO TOP

        DEFINE WINDOW oWnd  TITLE "Kart List" FROM 1,5 to 35.2,95

   @ 0,0 XBROWSE oBrw OF oWnd             ;
      COLUMNS 'ID', 'REF1', 'REF2'    ;
      HEADERS 'ID','REF1','REF2'              ;
      ALIAS 'KART'                    ;
      AUTOSORT  
      
        oBrw:nMarqueeStyle := 5
        oBrw:lRecordSelector := .f.
   
     
        ADD COLUMN TO XBROWSE oBrw AT 4 DATA NAMES->NAME;
        HEADER "FIRST NAME OF KART" SIZE 135          
        oBrw:aCols[4]:bLClickHeader := {|| MMMMM()}
       
        oBrw:CreateFromCode()
        oWnd:oClient   := oBrw
    ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()
RETURN

PROCEDURE MMMMM()
    MsgInfo("I want to change the XBrowse like test2 view")
RETURN

===========================================================
Image
test2.prg
Code: Select all  Expand view
#include "FiveWin.ch"
#include "XBrowse.Ch"
REQUEST DBFCDX
PROCEDURE MAIN()

   RDDSetDefault( 'DBFCDX' )

    USE KART NEW EXCLUSIVE
        INDEX ON ID TAG ID
        INDEX ON REF1 TAG REF1
    INDEX ON REF2 TAG REF2
    SET ORDER TO TAG ID

        USE NAMES NEW EXCLUSIVE
        INDEX ON ID TAG ID
        INDEX ON KID TAG KID
    INDEX ON NAME TAG NAME
    SET ORDER TO TAG NAME

    SET RELATION TO KID INTO KART
    
    GO TOP

        DEFINE WINDOW oWnd  TITLE "Kart List (Sorted Name)" FROM 1,5 to 35.2,95

   @ 0,0 XBROWSE oBrw OF oWnd             ;
      COLUMNS 'NAME'    ;
      HEADERS 'FIRST NAME OF KART'              ;
      ALIAS 'NAMES'                    ;
      AUTOSORT  

        oBrw:nMarqueeStyle := 5
        oBrw:lRecordSelector := .f.
   
     
        ADD COLUMN TO XBROWSE oBrw AT 1 DATA KART->ID;
        HEADER "ID"
        oBrw:aCols[1]:bLClickHeader := {|| MMMMM()}
       
        ADD COLUMN TO XBROWSE oBrw AT 2 DATA KART->REF1;
        HEADER "REF1"
        oBrw:aCols[2]:bLClickHeader := {|| MMMMM()}
        ADD COLUMN TO XBROWSE oBrw AT 3 DATA KART->REF2;       
        HEADER "REF2"
        oBrw:aCols[3]:bLClickHeader := {|| MMMMM()}
       
        oBrw:CreateFromCode()
        oWnd:oClient   := oBrw
    ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()
RETURN

PROCEDURE MMMMM()
    MsgInfo("I want back to change the XBrowse like test1 view")
RETURN



http://www.objekt.com.tr/fwh_test/relation.rar
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Advice needed about XBrowse usage!

Postby nageswaragunupudi » Thu Aug 27, 2009 2:51 am

Please try:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "XBrowse.Ch"

REQUEST DBFCDX

FIELD ID, KID

PROCEDURE MAIN()

   local oWnd, oBrw

   RDDSetDefault( 'DBFCDX' )

   // Assuming that indexes are already built

   USE NAMES NEW SHARED
   SET ORDER TO TAG KID

   USE KART NEW SHARED
   SET ORDER TO TAG ID
   SET RELATION TO ID INTO NAMES
   GO TOP

   DEFINE WINDOW oWnd  TITLE "Kart List" FROM 1,5 to 35.2,95

   @ 0,0 XBROWSE oBrw OF oWnd             ;
      FIELDS KART->ID, KART->REF1, KART->REF2, NAMES->NAME ;
      HEADERS 'ID','REF1','REF2', 'FIRST NAME OF KART'              ;
      ORDERS 'ID', 'REF1', 'REF2' ;
      ALIAS 'KART'

   oBrw:nMarqueeStyle     := 5
   oBrw:lRecordSelector   := .f.
   oBrw:aCols[ 4 ]:bLClickHeader := {|| MMMMM( oBrw ) }
   oBrw:CreateFromCode()
   oWnd:oClient           := oBrw

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()

RETURN

PROCEDURE MMMMM( oBrw )

   local cName := NAMES->NAME, nID := KART->ID

   if oBrw:cAlias == 'KART'
      KART->(  DbClearRelation() )
      NAMES->( OrdSetFocus( 'NAME' ), DbSetRelation( 'KART', { || KID }, 'KID' ), DbSeek( cName ) )

      oBrw:cAlias             := 'NAMES'
      oBrw:ID:cSortOrder      := nil
      oBrw:Ref1:cSortOrder    := nil
      oBrw:Ref2:cSortOrder    := nil
   else
      NAMES->( DbClearRelation(), OrdSetFocus( 'KID' ) )
      KART->(  DbSetRelation( 'NAMES', { || ID }, 'ID' ), DbSeek( nID ) )

      oBrw:cAlias             := 'KART'
      oBrw:ID:cSortOrder      := 'ID'
      oBrw:Ref1:cSortOrder    := 'REF1'
      oBrw:Ref2:cSortOrder    := 'REF2'

   endif

   oBrw:Refresh()

RETURN
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Advice needed about XBrowse usage!

Postby Horizon » Thu Aug 27, 2009 11:31 am

Thanks nageswaragunupudi,

I think This is my way to do this. When I run the prg, I noticed something. Is there any suggestion for it.

If I click directly 4th column header there is no problem.
But, if I click the Ref1 column header and then 4.th column It refresh the filter. There is no problem so far. Then I click the 4.th column header again, There is no KART.dbf data in the window. I could not understand it.

Any Suggestion?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Advice needed about XBrowse usage!

Postby nageswaragunupudi » Fri Aug 28, 2009 3:26 am

Please change this code :
Code: Select all  Expand view
KART->(  DbClearRelation() )

as
Code: Select all  Expand view
KART->(  DbClearRelation(), OrdSetFocus( 'ID' ) )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Advice needed about XBrowse usage!

Postby Horizon » Fri Aug 28, 2009 9:13 am

Thanks,

It works now.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Advice needed about XBrowse usage!

Postby Otto » Fri Aug 28, 2009 11:37 am

Hello Horizon,
would you be so kind to post the dbf and index files, too.
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6329
Joined: Fri Oct 07, 2005 7:07 pm

Re: Advice needed about XBrowse usage!

Postby Horizon » Fri Aug 28, 2009 12:22 pm

Hi,

This url is the same as my first message in this thread.

http://www.objekt.com.tr/fwh_test/relation.rar
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft and 67 guests