several questions about xBrowse

several questions about xBrowse

Postby ukservice » Fri Dec 16, 2011 10:33 pm

Hello,

This is my code:

Code: Select all  Expand view
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrw, oCol
   local cAlias

   // customer at c:\fwh\samples
   USE CUSTOMER NEW  ALIAS CUSTOMER
   pack
   GO TOP


   cAlias := Alias()





   DEFINE WINDOW oWnd TITLE "Invoice"

   @ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ALIAS "CUSTOMER" CELL LINES  //FASTEDIT



   oBrw:nMarqueeStyle       := 4
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:lColDividerComplete := .T.
   oBrw:nHeaderLines        := 1.5





   // Fast Edit
   oBrw:nEditTypes := EDIT_GET
   oBrw:lFastEdit := .t.



   //Keys
   oBrw:bPastEof = {||  x_AddBlank( oBrw )  }                  // A new line if trying to go down after the last row
   oBrw:bKeyDown :={ | nKey | x_Keys(nKey, oBrw, cAlias) }     //



   // First col
   oBrw:aCols[ 1 ]:nEditType := EDIT_GET_BUTTON
   oBrw:aCols[ 1 ]:bEditBlock := {|row, col, oCol| x_InsertData() }





   oBrw:bClrStd:={|| If(FIELD->MARRIED=.T.,{CLR_HRED,CLR_WHITE},{CLR_BLACK,CLR_WHITE})}







   oBrw:SetRDD()
   oBrw:CreateFromCode()




   oWnd:oClient   := oBrw



   ACTIVATE WINDOW oWnd MAXIMIZED
   CLOSE DATA

return (0)

//----------------------------------------------------------------------------//



//-----------------------------------------------------------------------------
FUNCTION x_Keys(nKey, oBrw, cAlias)

Do Case
   Case nKey == VK_DELETE
       if MsgNoYes("Want to Delete?","D E L E T E  AT "+cAlias)
          (cAlias)->(dbDelete())
          (cAlias)->(__dbPack())
           //oBrw:GoBottom()
           oBrw:Refresh()
       endif


 //Case nKey == VK_RETURN
 //      msgalert("enter")


   Case nKey == VK_INSERT
       x_AddBlank( oBrw )



EndCase

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





//-----------------------------------------------------------------------------
FUNCTION x_AddBlank( oBrw )

 DbGoBottom()
 APPEND BLANK

 oBrw:GoBottom()
 oBrw:refresh()

 oBrw:nColSel := 1
 oBrw:aCols[ 1 ]:edit()

RETURN NIL
//-----------------------------------------------------------------------------






function x_InsertData()

replace field->first with "LINE "+cvaltochar(recno())
replace field->last  with "RANDOM VALUE "+cvaltochar(nrandom(10))

RETURN NIL




I have some questions:

1.- Using the scroll, if trying to go down after the last row it executes bPastEof. Is it possible to limit that only to keydown´s key?.

2.- When adding a new line, I want to set the line to edit mode but I also want the button:
Image

Uploaded with ImageShack.us

3.- When I press enter, it goes to next field. If I press enter agan, I can edit the field. Is possible with ONE enter to go to next field and edit it?.

Thanks a lot.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: several questions about xBrowse

Postby RAMESHBABU » Sat Dec 17, 2011 5:45 am

Mr.UkService,

When I press enter, it goes to next field. If I press enter agan, I can edit the field. Is possible with ONE enter to go to next field and edit it?.


This is not the normal behaviour. But anyway, respecting your requirements, I made the required changes in your code. Just have a glance.
Read my comments made in UPPER CASE.

Regards

-Ramesh Babu P

Code: Select all  Expand view


#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrw, oCol
   local cAlias

   // customer at c:\fwh\samples
   USE CUSTOMER NEW  ALIAS CUSTOMER
   pack
   GO TOP

   cAlias := Alias()

   DEFINE WINDOW oWnd TITLE "Invoice"

   @ 0,0 XBROWSE oBrw OF oWnd AUTOCOLS ALIAS "CUSTOMER" CELL LINES  //FASTEDIT

   oBrw:nMarqueeStyle       := 4
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:lColDividerComplete := .T.
   oBrw:nHeaderLines        := 1.5

   *YOU HAVE TO REMOVE THIS WHEN YOU WANT THE CURSOR TO GO TO NEXT CELL WHEN PRESSING ENTER KEY
   // Fast Edit
   *oBrw:lFastEdit := .t.

   //Keys
   oBrw:bPastEof = {||  x_AddBlank( oBrw, cAlias )  }          // A new line if trying to go down after the last row
   oBrw:bKeyDown :={ | nKey | x_Keys(nKey, oBrw, cAlias) }     //

   // First col
   oBrw:aCols[ 1 ]:nEditType  := EDIT_GET_BUTTON
   oBrw:aCols[ 1 ]:bEditBlock := {|row, col, oCol| x_InsertData() }

   *IF YOU WANT TO EDIT SELECTED COLUMNS WITH EDIT BUTTON
   *oBrw:aCols[ 2 ]:nEditType  := EDIT_GET_BUTTON
   *oBrw:aCols[ 2 ]:bEditBlock := {|row, col, oCol| MsgInfo("WRITE YOUR FUNCTIONALITY HERE FOR COLUMN-2") }
   *oBrw:aCols[ 3 ]:nEditType  := EDIT_GET_BUTTON
   *oBrw:aCols[ 3 ]:bEditBlock := {|row, col, oCol| MsgInfo("WRITE YOUR FUNCTIONALITY HERE FOR COLUMN-3") }
   *oBrw:aCols[ 7 ]:nEditType  := EDIT_GET_BUTTON
   *oBrw:aCols[ 7 ]:bEditBlock := {|row, col, oCol| MsgInfo("WRITE YOUR FUNCTIONALITY HERE FOR COLUMN-7") }

   *IF YOU WANT EDIT_GET_BUTTON FOR ALL THE COLUMNS
   AEval(oBrw:aCols, {|x|x:nEditType := EDIT_GET_BUTTON})

   *WRITE bEditBlock for every column HERE

   oBrw:bClrStd:={|| If(FIELD->MARRIED=.T.,{CLR_HRED,CLR_WHITE},{CLR_BLACK,CLR_WHITE})}

   oBrw:SetRDD()
   oBrw:CreateFromCode()

   oWnd:oClient   := oBrw

   ACTIVATE WINDOW oWnd MAXIMIZED
   CLOSE DATA

return (0)

//-----------------------------------------------------------------------------

FUNCTION x_Keys(nKey, oBrw, cAlias)

local nOldKey

Do Case
   Case nKey == VK_DELETE
       if MsgNoYes("Want to Delete?","D E L E T E  AT "+cAlias)
          nOldKey := oBrw:KeyNo
          (cAlias)->(dbDelete())
          (cAlias)->(__dbPack())
          //oBrw:GoBottom()
          oBrw:KeyNo := MIN(nOldKey-1,RECCOUNT())
          oBrw:Refresh(.F.)
       endif

   Case nKey == VK_RETURN
        *THIS LINE MOVES THE CURSOR TO NEXT CELL
        oBrw:nColSel++ //msgalert("enter")
        *THIS LINE MOVES THE CURSOR BACK TO ORIGINAL CELL ON EDITING
        oBrw:aCols[oBrw:nColSel]:bOnPostEdit := {||oBrw:nColSel--}

   Case nKey == VK_INSERT
       x_AddBlank( oBrw, cAlias )

EndCase

return nil

//-----------------------------------------------------------------------------

FUNCTION x_AddBlank( oBrw, cAlias )

*THIS CONDITION WILL PREVENT AUTOMATIC PROCESSING OF bPatEof WHEN USED MOUSEWHEEL
if MsgNoYes("Want to Add new Record?","New Record in "+cAlias)
   APPEND BLANK
   oBrw:refreshCurrent()
   oBrw:nColSel := 1
   oBrw:aCols[ 1 ]:edit()
endif

RETURN NIL

//-----------------------------------------------------------------------------

function x_InsertData()

replace field->first with "LINE "+cvaltochar(recno())
replace field->last  with "RANDOM VALUE "+cvaltochar(nrandom(10))

RETURN NIL

//-----------------------------------------------------------------------------

 
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: several questions about xBrowse

Postby ukservice » Sat Dec 17, 2011 10:46 am

Mr. Ramesh,

Yes, thank you very much. It works as desired!!. Xbrowse is extraordinary great.

The only issue is that when I press enter and I type a value, when I press enter again changes are not saved.

How can I save them?.

Thanks a lot.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: several questions about xBrowse

Postby RAMESHBABU » Sat Dec 17, 2011 12:49 pm

Mr.ukservice,

Yes, thank you very much. It works as desired!!. Xbrowse is extraordinary great.


Happy to note that I could help you. :)

Change the bPostOnEdit line shown as under:

Code: Select all  Expand view

   Case nKey == VK_RETURN
        *THIS LINE MOVES THE CURSOR TO NEXT CELL
        oBrw:nColSel++ //msgalert("enter")
        *THIS LINE MOVES THE CURSOR BACK TO ORIGINAL CELL ON EDITING
       oBrw:aCols[oBrw:nColSel]:bOnPostEdit := {|x|x:Value := x:oEditGet:Value,oBrw:nColSel--}
 


- Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: several questions about xBrowse

Postby ukservice » Sun Dec 18, 2011 11:13 am

Mr. Ramesh,

Thank you very much again for your help. It works as desired.

One little last thing.

When doing double click it edits and selects the field with all field including spaces.

Is it possible to exclude spaces, as the picture?.

Image

Uploaded with ImageShack.us
Thanks again so much.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: several questions about xBrowse

Postby RAMESHBABU » Mon Dec 19, 2011 12:47 am

Mr.ukservice,

When doing double click it edits and selects the field with all field including spaces.

Is it possible to exclude spaces, as the picture?.


This is the default behaviour. You should be able to edit the field value to its
maximum width defined in the Structure.

In case you want to reduce the edit width, you have to use a PICTURE clause
for each Column.

Regards,

- Ramesh Babu P
User avatar
RAMESHBABU
 
Posts: 624
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: several questions about xBrowse

Postby ShumingWang » Mon Dec 19, 2011 2:58 am

::obrow := TXBrowse():New( odlg )
obrow:=::obrow
obrow:SetMySQL(odb2)

obrow:bKeyDown := {|nKey|::sto0120(nkey), if(::ledit,if(nKey==VK_DELETE .and. LEN(ALLTRIM(odb1:stockid))>0, (if(msgyesno2("删除这行吗?","请选择"),(::sto0103(odb2:qty,0,,.t.),odb2:DELETE(),obrow:Refresh()),)),if(nKey==VK_INSERT .and. LEN(ALLTRIM(odb1:stockid))>0,(obrow:gobottom(),obrow:godown()),)),) }

oCol := obrow:AddCol()
oCol:bStrData := { ||odb2:itemid}
oCol:cHeader := citemtitle+"编码"
ocol:beditvalue:={||odb2:itemid}
oCol:nedittype:= {||if(::ledit .and. LEN(ALLTRIM(odb1:stockid))>0.and.odb2:qty==0,EDIT_GET_BUTTON,0)}
oCol:bEditBlock:={||goods2brw(odb2:itemid,,,self,odb1:stockid)}
// itemid,lvalid,unitid,lmulti
oCol:cEditPicture:="@!"

oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:itemid,;
(if(!odb2:EOF(),;
(v:=goods2brw(v,.t.,@unitid2,self,odb1:stockid),odb2:unitpri:=sto0109(self,v),itemid1:=odb2:itemid,odb2:itemid:=v,mid1:=odb2:mid,unitid1:=odb2:unitid,odb2:unitid:=unitid2,odb2:SAVE()),;
(v:=goods2brw(v,.t.,@unitid2,self,odb1:stockid),odb2:unitpri:=sto0109(self,v),odb2:itemid:=v,odb2:invono:=::invono1,odb2:unitid:=unitid2,odb2:APPEND(),if(odb2:LASTREC()==1,::oget107:refresh(),));
));
, ;
) }
ocol:ctooltip:="可输入编码,名称规格,助记符或者一部分"

oCol := obrow:AddCol()
oCol:bStrData := { ||if(odb2:qty==0,"",odb2:qty)}
// show 0 as space
oCol:cHeader := "数量"
ocol:beditvalue:={||odb2:qty}
ocol:nedittype:={||if(::ledit.and.!odb2:EOF(),1,0)}
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:qty,(if(::sto0103(odb2:qty,v),(odb2:qty:=v,odb2:SAVE()),)),)}
oCol:nDataStrAlign := AL_RIGHT
oCol:cFooter :=" "
oCol:nFootStrAlign:= AL_RIGHT
oCol:nWidth := 65

Col := obrow:AddCol()
oCol:bStrData := { ||odb2:lfinish}
oCol:cHeader :={||if(lright, "结案","Hide")}
oCol:nEditType := {||if(::ledit .and. !odb2:EOF(),4,0)}
ocol:aEditListTxt:={" ","Y"}
ocol:aEditListBound:={" ","Y"}
oCol:bOnPostEdit := {|o, v, n| if( n != VK_ESCAPE .and. v != odb2:lfinish,(odb2:lfinish:=v,odb2:save()) , ) }
oCol:nWidth :=30

oCol := obrow:AddCol()
oCol:bStrData := { ||::cpath1+"\sub\"+cvaltochar(odb2:imgid)+".jpg"}
oCol:cHeader := "图片"
ocol:cdatatype:="F"

// we change oCol:cHeader and oCol:nEditType to block, so can dynamic control


Shuming Wang
http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
ShumingWang
 
Posts: 465
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Re: several questions about xBrowse

Postby ukservice » Mon Dec 19, 2011 9:07 am

Thank you very much.

I tried oBrw:aCols[ 2 ]:cEditPicture:="@!" but does not work.

What is the picture clause to remove spaces?.

Thank you very much.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: several questions about xBrowse

Postby ukservice » Tue Dec 20, 2011 5:37 pm

up
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: several questions about xBrowse

Postby ukservice » Thu Dec 22, 2011 10:33 am

up
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John

Re: several questions about xBrowse

Postby Enrico Maria Giordano » Thu Dec 22, 2011 8:52 pm

A picture to remove spaces doesn't exist, as far as I know.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: several questions about xBrowse

Postby hua » Fri Dec 23, 2011 6:55 am

Enrico Maria Giordano wrote:A picture to remove spaces doesn't exist, as far as I know

I think so too.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: several questions about xBrowse

Postby ukservice » Mon Dec 26, 2011 10:45 am

Thank you very much.

Mr. Rao said:

oBrw:aCols[n]:bEditValue := { |x| If( x == nil, Trim(<fieldname>), ( <fieldname> := x, Trim(x) ) }

I do not know why you want this behavior. Users will not be able to enter longer value than the trimmed value shown in the browse
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
User avatar
ukservice
 
Posts: 417
Joined: Tue Feb 23, 2010 3:09 pm
Location: John


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 50 guests