Page 1 of 1
A Few question about XBrowse.
Posted:
Sun Sep 07, 2008 2:24 pm
by Horizon
Hi,
1) I want to select a row with enter key. How Can I? I can do it with double click.
2) I have added a button to sample (thanks to nageswaragunupudi) below. Before than I can use the XBrowse object as a default, but after added the button in order to choice from xbrowse i must select it. I wrote the oBrw:SetFocus() on Dialog ON INIT. It did not change anything. How can i focus the XBrowse when i activate the dialog.
Thanks,
- Code: Select all Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'
REQUEST DBFCDX
function Main()
local oDlg, oBrw
local oSeek, cSeek := Space(25)
USE CUSTOMER NEW ALIAS CUST SHARED VIA 'DBFCDX'
SET ORDER TO TAG SALARY
GO TOP
DEFINE DIALOG oDlg SIZE 540,480 PIXEL
@ 10, 10 XBROWSE oBrw ;
COLUMNS 'First','Last','Salary' ;
SIZE 250,200 PIXEL ;
OF oDlg ;
ALIAS 'CUST' ;
AUTOSORT
@ 220, 10 SAY oSeek VAR cSeek SIZE 100,10 PIXEL OF oDlg ;
COLOR CLR_BLACK, CLR_YELLOW
@ 220, 210 BUTTON "&OK" PIXEL OF oDlg
oBrw:bSeek := { |cSeek| CUST->( DbSeek( Val( cSeek ), .t. ), !eof() ) }
oBrw:oSeek := oSeek
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED on INIT oBrw:SetFocus()
return nil
Posted:
Sun Sep 07, 2008 5:47 pm
by nageswaragunupudi
If you want to show a picklist from a dbf ( or any source ) for selection, Xbrowse provides a very simple one line code. Please compile the following sample
- Code: Select all Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'
function main()
local cState := Space( 2 )
USE STATES NEW SHARED
XBROWSER 'STATES' SELECT ( cState := STATES->Code )
if Empty( cState )
MsgInfo( 'Not Selected' )
else
MsgInfo( 'Selected ' + cState )
endif
return nil
The one line code "XBROWSER 'STATES' SELECT ( cState := STATES->Code )" displays States in a suitably sized xbrowse dialog with "select" button. If the button is clicked the selection is made.
Posted:
Sun Sep 07, 2008 5:54 pm
by nageswaragunupudi
Here is a screen shot of what the above one line of code can produce
Posted:
Sun Sep 07, 2008 6:52 pm
by Horizon
Thanks nageswaragunupudi.
But I could not find any documentation about XBROWSER. I could not compile the code you have given. does XBROWSER support the bSeek Method?
Posted:
Mon Sep 08, 2008 12:09 am
by nageswaragunupudi
This requires FWH 8.08. Please read whatsnew.txt
Posted:
Mon Sep 08, 2008 8:19 am
by Horizon
Hmmm. I think I should upgrade the FWH.
Just one question. How Can I detect ENTER key and assign a procedure?
Thanks,
Posted:
Mon Sep 08, 2008 8:35 am
by fafi
Try this :
- Code: Select all Expand view
** this browse for detail invoice
@145,2 XBROWSE oBrw1 ;
COLUMNS "DI_ITMABV" ,;
"DI_MUNITS" ,;
"DI_SALEPRC" ,;
"DI_UNTPRC" ,;
"DI_INVQTY" ,;
"DI_DISCNT" ,;
"DI_EXTDAMT" ;
OF oDlg ;
SIZE 390,75 PIXEL ;
PICTURE "@!","@!","9999.99","9999.99","9999.99","99.99%","9999.999" ;
COLSIZES 270,50,80,80,80,80,80 ;
HEADERS "Item Description",;
"Unit",;
"Default Price",;
"Sale Price",;
"Quantity",;
"Discount",;
"Amount" ;
ALIAS "dinvoice"
oBrw1:bKeyDown := { |nKey,nFlag| DetailAction(nKey,oBrw1) }
if ! Empty( oCol := oBrw1:aCols[4] ) // Price
oCol:nEditType := EDIT_GET
oCol:bOnPostEdit := {| o, u, n| PostEditDetail( o, u, n ) }
endif
if ! Empty( oCol := oBrw1:aCols[5] ) // Quantity
oCol:nEditType := EDIT_GET
oCol:bOnPostEdit := {| o, u, n| PostEditDetail( o, u, n ) }
endif
if ! Empty( oCol := oBrw1:aCols[6] ) // Discount
oCol:nEditType := EDIT_GET
oCol:bOnPostEdit := {| o, u, n| PostEditDetail( o, u, n ) }
endif
XbrStyles( oBrw1 )
oBrw1:CreateFromCode()
************** create this function
static function PostEditDetail( oCol, xValue, nLastKey )
local nOldVal, nFldNo,nCol := oCol:nPos
local cAlias := oCol:oBrw:cAlias
if nLastKey == 13 // this is enter
nOldVal := Eval( oCol:bEditValue )
if !( nOldVal == xValue )
if dinvoice->(dbrLock())
do case
case nCol == 4 // price
dinvoice->DI_UNTPRC := xValue
case nCol == 5 // quantity
dinvoice->DI_INVQTY := xValue
case nCol == 6 // discount
dinvoice->DI_DISCNT := xValue
endcase
nHarga := dinvoice->DI_UNTPRC * dinvoice->DI_INVQTY
nDisc := 0
if dinvoice->DI_DISCNT # 0
nDisc := nHarga * ( dinvoice->DI_DISCNT / 100 )
endif
nTotal := nHarga - nDisc
dinvoice->DI_EXTDAMT := nTotal
dinvoice->( dbUnlock() )
SumTotalHeader()
endif
endif
oCol:oBrw:goRight()
endif
return nil
Best Regards
Fafi
Posted:
Mon Sep 08, 2008 9:18 am
by Horizon
Thank you for your reply Fafi.
But I use xbrowse as a picklist. I do not edit any field in the xbrowse. I only want to select the row.
I'll try to use the code you posted. thanks again.
Posted:
Mon Sep 08, 2008 1:53 pm
by James Bott
Hakan,
>How Can I detect ENTER key and assign a procedure?
Add the DEFAULT clause to your button definition.
Regards,
James
Posted:
Mon Sep 08, 2008 2:40 pm
by Horizon
Thanks James,
There are two condition.
1) There is a button and default.
2) There is not button.
1) if i add the button, user should focus the xbrowse and than choice the desired row and press ENTER to select. It is not usable for user.
2) if i did not add the button, xbrowse is default. it is ok. user can choice the row and ENTER to select.
I need the 2. condition now. I have not any button. I need the select enter key like ON DBLCLICK.
Thanks,
Posted:
Mon Sep 08, 2008 2:48 pm
by James Bott
Without a button try:
oBrw:bKeydown := {|nKey,nFlags| ;
IIF(nKey == VK_RETURN, doWhatever(), oDlg:end(),)}
Posted:
Mon Sep 08, 2008 3:05 pm
by Antonio Linares
James,
A little typo in your code: the dialog should be closed when enter is pressed. Edited: ops, no its a missing "(" only
Hakan, here you have your example working:
- Code: Select all Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'
REQUEST DBFCDX
function Main()
local oDlg, oBrw
local oSeek, cSeek := Space(25)
USE CUSTOMER NEW ALIAS CUST SHARED VIA 'DBFCDX'
SET ORDER TO TAG SALARY
GO TOP
DEFINE DIALOG oDlg SIZE 540,480 PIXEL
@ 10, 10 XBROWSE oBrw ;
COLUMNS 'First','Last','Salary' ;
SIZE 250,200 PIXEL ;
OF oDlg ;
ALIAS 'CUST' ;
AUTOSORT
oBrw:bKeyDown = { | nKey, nFlags | If( nKey == VK_RETURN, oDlg:End(),) }
oBrw:bLDblClick = { || oDlg:End() }
@ 220, 10 SAY oSeek VAR cSeek SIZE 100,10 PIXEL OF oDlg ;
COLOR CLR_BLACK, CLR_YELLOW
@ 220, 210 BUTTON "&OK" PIXEL OF oDlg ACTION oDlg:End()
oBrw:bSeek := { |cSeek| CUST->( DbSeek( Val( cSeek ), .t. ), !eof() ) }
oBrw:oSeek := oSeek
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED
return nil
edited: added code for closing wirth double click too
Posted:
Mon Sep 08, 2008 3:31 pm
by James Bott
Antonio,
>A little typo in your code: the dialog should be closed when enter is pressed.
Ops. I meant it to be:
oBrw:bKeydown := {|nKey,nFlags| ;
IIF(nKey == VK_RETURN, ( doWhatever(), oDlg:end() ), ) }
James
Posted:
Mon Sep 08, 2008 8:48 pm
by Horizon
Thank you very much James, Antonio.
It works perfectly.
Antonio : How Can get the new TComboBox class?
Posted:
Mon Sep 08, 2008 10:57 pm
by Antonio Linares
Hakan,
> How Can get the new TComboBox class?
Please check your email