xBrowse multi selects (resolvido)

Post Reply
User avatar
ip_ram
Posts: 43
Joined: Tue Nov 21, 2006 4:07 pm
Location: Brazil / MG / Belo Horizonte

xBrowse multi selects (resolvido)

Post by ip_ram »

Olá!
Preciso selecionar várias linhas em um xBrowse (uso MySQL).
Vou mostrar uma lista de clientes e o usuário seleciona quais ele deseja.
Alguém indica um exemplo?
Obrigado!

Hello!
I need to select multiple rows in an xBrowse (MySQL usage).
I will show a list of clients and the user selects which ones he wants.
Does anyone indicate an example?
Thank you!

Rodrigo Melo
Belo Horizonte / MG
Brasil
Last edited by ip_ram on Tue Sep 25, 2018 8:09 pm, edited 1 time in total.
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: xBrowse multi selects

Post by cnavarro »

C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
ip_ram
Posts: 43
Joined: Tue Nov 21, 2006 4:07 pm
Location: Brazil / MG / Belo Horizonte

Re: xBrowse multi selects

Post by ip_ram »

Navarro,

Gracias.
User avatar
ip_ram
Posts: 43
Joined: Tue Nov 21, 2006 4:07 pm
Location: Brazil / MG / Belo Horizonte

Re: xBrowse multi selects

Post by ip_ram »

Navarro,

Após selecionar os registros no browse (oBrw) como recuperar os registros selecionados em aPes?

Code: Select all

Function GrupoListarPessoa()

    Local oDlg, oBrw, oSay, oPar, oCon, oRet, lRet := .f. 
    
    If ! Conectar(.f.)
        Return(Nil)
    EndIf
    oPar := oDba:RowSet("select id,nom_pes from tb_pes order by nom_pes",,.t.)
    If oPar == Nil
        Return(lRet)
    EndIf

    Define Dialog oDlg Title "Selecionar Participantes" Size 516,358 Of oWnd Pixel

    @ 28,2 xBrowse oBrw Of oDlg DataSource oPar ;
             Columns 'id','nom_pes' ;
             Headers 'ID','Pessoa' ;
             Pictures "999","@A" ;
             ColSizes 60,400 ;
             Font oFnt2 Size 255,150 Pixel UpDate Cell AutoSort

    oBrw:nMarqueeStyle    := 5
    oBrw:nDataType           := 64
    oBrw:nRowDividerStyle := 3
    oBrw:nColDividerStyle := 2

    With Object oBrw:InsCol(1)
        :bEditValue    := { || AScan( oBrw:aSelected, oBrw:BookMark ) > 0 }
        :SetCheck()
        :nHeadBmpNo    := { || If( Len( oBrw:aSelected ) == oBrw:nLen, 1, 2 ) }
    End

    oBrw:bLClicked := { |r,c,f,oBrw| If( oBrw:MouseColPos( c ) == 1 , ;
                   If( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0, ;
                     AAdd( oBrw:aSelected, oBrw:BookMark ), ;
                     ADel( oBrw:aSelected, f, .t. ) ), Nil ), ;
                     oBrw:RefreshCurrent() }

    oBrw:aCols[1]:nHeadStrAlign := 2
    oBrw:aCols[2]:nHeadStrAlign := 2
    oBrw:aCols[3]:nHeadStrAlign := 0
    oBrw:aJustify                    := {2,1,0}

    oBrw:bOnRefresh := { || oSay:Refresh() }

    @ 8,05 Say 'Selecionados:' Of oDlg Pixel Font oFnt2
    @ 8,48 Say oSay Prompt Len(oBrw:aSelected) Size 12,12 Of oDlg Pixel Font oFnt2 Picture '99'

    @ 6,190 BTNBMP oCon Resource 'sel26' Of oDlg Size 32,16 Pixel 2007 ;
              Action(lRet:=.t.,oDlg:End()) ToolTip "Confirmar os selecionados"
    @ 6,226 BTNBMP oRet Resource 'sair16' Of oDlg Size 32,16 Pixel 2007 ;
              Action(lRet:=.f.,oDlg:End()) ToolTip "Retornar"

    oBrw:SetMySQL(oPar)
    oBrw:CreateFromCode()

    oDlg:oClient   := oBrw
    oDlg:lHelpIcon := .f.

    Activate Dialog oDlg Centered On Init oBrw:SetFocus()
 
    If lRet
        If Len(oBrw:aSelected) > 0
            aPes := oBrw:aSelected
        EndIf
    EndIf

Return(lRet)
 
Gracias

Rodrigo Melo
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: xBrowse multi selects

Post by cnavarro »

Rodrigo, intenta con oBrw:aSelected
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
ip_ram
Posts: 43
Joined: Tue Nov 21, 2006 4:07 pm
Location: Brazil / MG / Belo Horizonte

Re: xBrowse multi selects (resolvido)

Post by ip_ram »

Navarro,

Resolvido assim:

Code: Select all

Function GrupoListarPessoa()

    Local oDlg, oBrw, oSay, oPar, oCon, oRet, lRet := .f. 
    
    If ! Conectar(.f.)
        Return(Nil)
    EndIf
    oPar := oDba:RowSet("select id,nom_pes from tb_pes order by nom_pes",,.t.)
    If oPar == Nil
        Return(lRet)
    EndIf

    Define Dialog oDlg Title "Selecionar Participantes" Size 516,358 Of oWnd Pixel

    @ 28,2 xBrowse oBrw Of oDlg DataSource oPar ;
             Columns 'id','nom_pes' ;
             Headers 'ID','Pessoa' ;
             Pictures "999","@A" ;
             ColSizes 60,400 ;
             Font oFnt2 Size 255,150 Pixel UpDate Cell AutoSort

    oBrw:nMarqueeStyle    := 5
    oBrw:nDataType           := 64
    oBrw:nRowDividerStyle := 3
    oBrw:nColDividerStyle := 2

    With Object oBrw:InsCol(1)
        :bEditValue    := { || AScan( oBrw:aSelected, oBrw:BookMark ) > 0 }
        :SetCheck()
        :nHeadBmpNo    := { || If( Len( oBrw:aSelected ) == oBrw:nLen, 1, 2 ) }
    End

    oBrw:bLClicked := { |r,c,f,oBrw| If( oBrw:MouseColPos( c ) == 1 , ;
                   If( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0, ;
                     AAdd( oBrw:aSelected, oBrw:BookMark ), ;
                     ADel( oBrw:aSelected, f, .t. ) ), Nil ), ;
                     oBrw:RefreshCurrent() }

    oBrw:aCols[1]:nHeadStrAlign := 2
    oBrw:aCols[2]:nHeadStrAlign := 2
    oBrw:aCols[3]:nHeadStrAlign := 0
    oBrw:aJustify                    := {2,1,0}

    oBrw:bOnRefresh := { || oSay:Refresh() }

    @ 8,05 Say 'Selecionados:' Of oDlg Pixel Font oFnt2
    @ 8,48 Say oSay Prompt Len(oBrw:aSelected) Size 12,12 Of oDlg Pixel Font oFnt2 Picture '99'

    @ 6,190 BTNBMP oCon Resource 'sel26' Of oDlg Size 32,16 Pixel 2007 ;
              Action(lRet:=.t.,aPes:=GrupoRecuperarPessoa(oBrw,oPar),oDlg:End()) ToolTip "Confirmar os selecionados"
    @ 6,226 BTNBMP oRet Resource 'sair16' Of oDlg Size 32,16 Pixel 2007 ;
              Action(lRet:=.f.,aPes:={},oDlg:End()) ToolTip "Retornar"

    oBrw:SetMySQL(oPar)
    oBrw:CreateFromCode()

    oDlg:oClient   := oBrw
    oDlg:lHelpIcon := .f.

    Activate Dialog oDlg Centered On Init oBrw:SetFocus()

Return(lRet)

Function GrupoRecuperarPessoa(oBrw,oPar)

    Local aVet := {}, nCtr := 0

    If Len(oBrw:aSelected) > 0
        For nCtr := 1 To Len(oBrw:aSelected)
            oPar:GoTo(oBrw:aSelected[nCtr])
            AAdd(aVet,oPar:Id)
        Next
    EndIf

Return(aVet)
 
Agradecimento ao JMSilva (silva.ifsp@gmail.com).

Um abraço!

Rodrigo Melo
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: xBrowse multi selects (resolvido)

Post by nageswaragunupudi »

oBrw:nDataType := 64
This is wrong.
Correct nDataType is DATATYPE_ODBF (16)

XBrowse automatically decides the correct datatype, when you create the browse based on the type of DATASOURCE.
Not only that you do not have to assign the value yourself, but it is also highly undesirable as in the above case.
Regards

G. N. Rao.
Hyderabad, India
User avatar
ip_ram
Posts: 43
Joined: Tue Nov 21, 2006 4:07 pm
Location: Brazil / MG / Belo Horizonte

Re: xBrowse multi selects (resolvido)

Post by ip_ram »

Rao,

Tks.
Post Reply