Page 1 of 2

FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Apr 14, 2021 5:04 am
by nageswaragunupudi
We are aware that the user can change the sort order of columns by clicking on the header in autosort mode.

There are many programmers who like to provide a combobox to change the sort order additionally. In this case, programmers are often facing difficulty in perfectly synchronizing the combobox and the built-in sort by clicking the header.

This process is extremely simplified by introducing oBrw:oSortCbx and internally managing the combobox.

There are two ways of creating:
Method-1: Recommended
Code: Select all  Expand view

// after creating the browse and calling oBrw:CreatefromCode()
@ r,c COMBOBOX oBrw:oComboCbx VAR oBrwL:cSortOrder SIZE w,h PIXEL OF oDlg/oWnd/oBar
 


Rest is fully taken care of by the XBrowse.

Method-2: This method also works
Code: Select all  Expand view

local cOrder := ""

@ r,c COMBOBOX oCbx VAR cOrder SIZE w,h PIXEL OF oDlg/oWnd/oBar

@ r,c XBROWSE oBrw ........... DATASOURCE <src> .........
...
oBrw:oSortCbx := oCbx
oBrw:CreateFromCode()
 


This is a sample program:
Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDlg, oBrw

   USE CUSTOMER NEW VIA "DBFCDX"
   SET ORDER TO TAG FIRST
   GO TOP

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE ALIAS() AUTOCOLS AUTOSORT ;
      CELL LINES NOBORDER

   oBrw:CreateFromCode()

   @ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

return nil
 


Image

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Thu Apr 15, 2021 7:23 am
by Silvio.Falconi
marvelous

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Thu Apr 15, 2021 12:55 pm
by nageswaragunupudi
Silvio.Falconi wrote:marvelous

Made for You :)

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Thu Apr 15, 2021 2:55 pm
by Marc Venken
Very Nice and helpfull. I was in the progress of integrating this.

A pending request (but not that high on a todo list) could be to select colums in one process.

I see in the sample above that you have to click 4 times on the header and select 4 times the column to unselect for the browse.
My idea by this :

I open the browse with all columns. select the ones that I need to process and save the state of the browse.
Next time I open just one of the created browses statusses and I have the browse that I want.
So a load and save state would be SUPER ))

This would in my case eliminated the need to program folders where I mostly group different items from the same database (basic data, digital media, values, ...)

Maybe a postion on the TODO list.

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Tue Jun 01, 2021 10:01 am
by Silvio.Falconi
nageswaragunupudi wrote:
Silvio.Falconi wrote:marvelous

Made for You :)


Nages,
as I wrote you I tried it with Tdatabase and I not see any data on combobox

Code: Select all  Expand view


#include "fivewin.ch"

 REQUEST DBFCDX


function Main()

   local aData

   FERASE( "CUSTOMER.CDX" )
   USE CUSTOMER NEW EXCLUSIVE VIA "DBFCDX"
   aData := FW_DbfToArray( "FIRST,LAST,STREET", , { || RECNO() < 11 } )
   GO TOP
   FW_CdxCreate()
   CLOSE CUSTOMER

 
      UsageTdatabase()

return nil
//-----------------------------------------------------------------------------------//

 function UsageTdatabase()

   local oDlg, oBrw
   local oClienti
   local oGet
   local cSeek:=space(100)

   oCustomer:= TCustomer():New()

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE


    @ 10, 165 GET oGet VAR cSeek SIZE 280,24 PIXEL OF oDlg


   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oCustomer AUTOCOLS AUTOSORT ;
      NOBORDER LINES

   WITH OBJECT oBrw
     :lIncrFilter   := .t.
     :oSeek         := oGet

      :CreateFromCode()
   END

   @ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

   CLOSE DATA

   return nil
//-----------------------------------------------------------------------------------//
CLASS TXData from TDataBase
     DATA cDbfPath init  cFilePath(GetModuleFileName( GetInstance() ))
     DATA cExePath init  cFilePath(GetModuleFileName( GetInstance() ))
  ENDCLASS

  CLASS TCustomer from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TCustomer
   Default lShared := .t.
   ::super:New(,::cDbfPath + "Customer" ,, lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
   RETURN Self

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Tue Jun 01, 2021 11:15 am
by nageswaragunupudi
oSortCbx is for sorting columns.
Works with DBF, TDatabase, ADO and others.

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Tue Jun 01, 2021 12:56 pm
by nageswaragunupudi
Test with TDatabase
Code: Select all  Expand view
function TestTDatabase()

   local oDlg, oBrw, oDbf

   oDbf  := TDatabase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
   oDbf:SetOrder( "FIRST" )
   oDbf:GoTop()

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf AUTOCOLS ;
      AUTOSORT ;
      NOBORDER CELL LINES

   WITH OBJECT oBrw
      :CreateFromCode()
   END

   @ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

   oDbf:Close()

return nil

This is working as expected

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Tue Jun 01, 2021 8:50 pm
by Silvio.Falconi
nageswaragunupudi wrote:Test with TDatabase
Code: Select all  Expand view
function TestTDatabase()

   local oDlg, oBrw, oDbf

   oDbf  := TDatabase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
   oDbf:SetOrder( "FIRST" )
   oDbf:GoTop()

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf AUTOCOLS ;
      AUTOSORT ;
      NOBORDER CELL LINES

   WITH OBJECT oBrw
      :CreateFromCode()
   END

   @ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

   oDbf:Close()

return nil

This is working as expected




sorry, i beg your pardon i am mortified, it was my mistake i forgot a comma and everything was not working!!!!

because I have my dbf config

Code: Select all  Expand view
local aCols    := { ;
                { "CliCognome"     , "Cognome",,        120},;
                { "CliNome"        , "Nome"   ,,        120 },;
                { "CliFiscale"     , "Codice Fiscale",, 100 },;
                { "CliPartiva"     , "Partita Iva",,    110 },;
                { "CliIndiriz"     , "Indirizzo",,      120 },;
                { "CliPaese"       , "Località",,       120 },;
                { "CliCap"         , "Cap", ,            60 },;
                { "CliProv"        , "Provincia",,       40 },;
                { "CliRegione"     , "Regione", ,        90 },;
                { "CliTelef1"      , "Cellulare",,      100 },;
                { "CliTelef2"      , "Telefono",,       100 },;
                { "CliEmail"       , "Email", ,         140 },;
                { "CliSitoWeb"     , "Sito Web",,       140 },;
                { "CliAppunti"     , "Appunti", ,       200 }}


I had put a single comma for each line
sorry again
Now all is worKing with Tdatabase

Image

I make a test "all together" ( csortbox, search,multisel)

even if tonight working and trying to find a customer I realized that it does not refresh the index on which to search that is

if I initially look for the name "Angelo" and place the combobox in the "Name" column,

it looks for me all the records that have the "Name" = "Angelo" field.

Then if I change the combobox item and decide to search on another column,

for example "Location", the procedure rests to search for the cseek again on the "Name" column

I tried to add the change ast the combobox

@ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg ;
ON CHANGE ( oBrw:Seek( "" ), ;
oBrw:cFilterFld := oBrw:oCol( oBrw:cSortOrder ):cExpr, ;
oBrw:SetFocus() )

It run but I wish Know if this is right for you, thanks

at last , When we select a column of xbrowse ( Autosort) it refresh also the combobox but not refresh the index need for the search, which remains the previous one

How resolve this ?

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Jun 02, 2021 2:39 am
by nageswaragunupudi
Please test this
Code: Select all  Expand view
function TestTDatabase()

   local oDlg, oBrw, oDbf

   oDbf  := TDatabase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
   oDbf:SetOrder( "FIRST" )
   oDbf:GoTop()

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oDbf AUTOCOLS ;
      AUTOSORT ;
      NOBORDER CELL LINES

   WITH OBJECT oBrw
      :lIncrFilter   := .t.
      :bOnSort       := { |b,oCol| oBrw:Seek( "" ), ;
                             oBrw:cFilterFld := oCol:cExpr, ;
                             oBrw:SetFocus() }
      //
      :CreateFromCode()
   END

   @ 10, 20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg
   @ 10,140 SAY oBrw:oSeek PROMPT oBrw:cSeek SIZE 200,24 PIXEL OF oDlg COLOR CLR_HRED,CLR_YELLOW

   ACTIVATE DIALOG oDlg CENTERED

   oDbf:Close()

return nil
 

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Jun 02, 2021 6:36 am
by Silvio.Falconi
thanks Rao
do have have a ssmple to put combobox and srarch on topbar of xbrowse?

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Jun 02, 2021 6:59 am
by nageswaragunupudi
I suggest you do not use topbar unless it is no other way
To the extent possible, put all your controls on the dialog only.

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Jun 02, 2021 8:41 am
by Silvio.Falconi
nageswaragunupudi wrote:I suggest you do not use topbar unless it is no other way
To the extent possible, put all your controls on the dialog only.


ok thanks

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Jun 02, 2021 6:08 pm
by TimStone
Following your examples, I wanted to show a box on the dialog to provide feedback for the keys typed, and to allow the selection of the column. I use resources, so I added this:

in Program
Code: Select all  Expand view
  REDEFINE SAY oLBxin:oSeek PROMPT oLBxin:cSeek ID 8001 OF oDiw
   REDEFINE COMBOBOX oLBxin:oSortCbx VAR oLBxin:cSortOrder ID 8002 OF oDiw
 


In Resource
Code: Select all  Expand view
    LTEXT                      "",8001,50,150,165,13
    COMBOBOX        8002,250,210,100,110,CBS_DROPDOWN | WS_BORDER | WS_VSCROLL | WS_TABSTOP
 


1) I want the SAY to reflect the letters as they are typed. Perhaps a GET would be better ?
2) My field names do not match Headers. So if i want to display the Header list in my combobox, what would be the command ?

Thanks.

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Wed Jun 02, 2021 6:34 pm
by nageswaragunupudi
REDEFINE SAY oLBxin:oSeek PROMPT oLBxin:cSeek ID 8001 OF oDiw
REDEFINE COMBOBOX oLBxin:oSortCbx VAR oLBxin:cSortOrder ID 8002 OF oDiw


These two lines should be after defining the xbrowse oLbxin.

Also, my field names do not match Headers. So if i want to display the Header list in my combobox, what would be the command ?

You need revised xbrowse.prg
We will send you to your email

Re: FWH 2103: XBrowse: oSortCbx

PostPosted: Mon Jun 07, 2021 9:11 pm
by Silvio.Falconi
thanks rao

Image

all seem to run ok
i managed to put the search get and combo in the vtaskbar menu and everything works

a question....
I insert these columns on xbrowse

Code: Select all  Expand view
{ "CliCognome"     , "Cognome",,        120},;
                { "CliNome"        , "Nome"   ,,        120 },;
                { "CliFiscale"     , "Codice Fiscale",, 100 },;
                { "CliPartiva"     , "Partita Iva",,    110 },;
                { "CliIndiriz"     , "Indirizzo",,      120 },;
                { "CliPaese"       , "Località",,       120 },;
                { "CliCap"         , "Cap", ,            60 },;
                { "CliProv"        , "Provincia",,       40 },;
                { "CliRegione"     , "Regione", ,        90 },;
                { "CliTelef1"      , "Cellulare",,      100 },;
                { "CliTelef2"      , "Telefono",,       100 },;
                { "CliEmail"       , "Email", ,         190 },;
                { "CliSitoWeb"     , "Sito Web",,       140 },;
                { "CliAppunti"     , "Appunti", ,       200 }}



If I wish have on cSortBox only some columns of the xbrowse not all

{ "CliCognome" , "Cognome",, 120},;
{ "CliNome" , "Nome" ,, 120 },;

{ "CliPaese" , "Località",, 120 },;
{ "CliCap" , "Cap", , 60 },;
{ "CliProv" , "Provincia",, 40 },;
{ "CliRegione" , "Regione", , 90 },;


how I can to make only these ?

it's possible ?

that is my head tells me that I have to remove the AUTOSORT command and I have to set every column I want to create the sort but how to do it?