Page 1 of 1

xBrowse multi selects (resolvido)

Posted: Tue Sep 18, 2018 3:49 pm
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

Re: xBrowse multi selects

Posted: Tue Sep 18, 2018 4:05 pm
by cnavarro

Re: xBrowse multi selects

Posted: Tue Sep 18, 2018 4:36 pm
by ip_ram
Navarro,

Gracias.

Re: xBrowse multi selects

Posted: Sat Sep 22, 2018 11:06 pm
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

Re: xBrowse multi selects

Posted: Sat Sep 22, 2018 11:21 pm
by cnavarro
Rodrigo, intenta con oBrw:aSelected

Re: xBrowse multi selects (resolvido)

Posted: Tue Sep 25, 2018 1:17 am
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

Re: xBrowse multi selects (resolvido)

Posted: Tue Sep 25, 2018 11:25 pm
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.

Re: xBrowse multi selects (resolvido)

Posted: Wed Sep 26, 2018 1:16 am
by ip_ram
Rao,

Tks.