Here is a new control "ComboSearchGrid".
Code: Select all
#include "hmg.ch"
#command @ <row>, <col> COMBOSEARCHGRID <name> ;
[ <dummy1: OF, PARENT> <parent> ] ;
[ HEIGHT <height> ] ;
[ WIDTH <width> ] ;
[ VALUE <value> ] ;
[ FONT <fontname> ] ;
[ SIZE <fontsize> ] ;
[ <bold : BOLD> ] ;
[ <italic : ITALIC> ] ;
[ <underline : UNDERLINE> ] ;
[ TOOLTIP <tooltip> ] ;
[ BACKCOLOR <backcolor> ] ;
[ FONTCOLOR <fontcolor> ] ;
[ MAXLENGTH <maxlenght> ] ;
[ <upper: UPPERCASE> ] ;
[ <lower: LOWERCASE> ] ;
[ <numeric: NUMERIC> ] ;
[ ON GOTFOCUS <gotfocus> ] ;
[ ON LOSTFOCUS <lostfocus> ] ;
[ ON ENTER <enter> ] ;
[ <RightAlign: RIGHTALIGN> ] ;
[ <notabstop: NOTABSTOP> ] ;
[ HELPID <helpid> ] ;
[ ITEMS <aitems> ] ;
[ <anywhere :ANYWHERESEARCH> ];
[ HEADERS <aheaders> ] ;
[ WIDTHS <awidths>] ;
=>;
_DefineComboSearchGrid( <"name">, <"parent">, <col>, <row>, <width>, <height>, <value>, ;
<fontname>, <fontsize>, <tooltip>, <maxlenght>, ;
<.upper.>, <.lower.>, <.numeric.>, ;
<{lostfocus}>, <{gotfocus}>, <{enter}>, ;
<.RightAlign.>, <helpid>, <.bold.>, <.italic.>, <.underline.>, <backcolor> , <fontcolor> , <.notabstop.>, <aitems>,<.anywhere.> ,<aheaders>,<awidths>)
#xcommand ANYWHERESEARCH <sort> ;
=>;
_HMG_SYSDATA \[ 464 \] := <sort>
#xcommand DEFINE COMBOSEARCHGRID <name>;
=>;
_HMG_SYSDATA \[ 416 \] := <"name"> ;; //name
_HMG_SYSDATA \[ 417 \] := Nil ;; //parent
_HMG_SYSDATA \[ 431 \] := Nil ;; //row
_HMG_SYSDATA \[ 432 \] := Nil ;; //col
_HMG_SYSDATA \[ 421 \] := Nil ;; // height
_HMG_SYSDATA \[ 420 \] := Nil ;; // width
_HMG_SYSDATA \[ 434 \] := Nil ;; //value
_HMG_SYSDATA \[ 422 \] := Nil ;; //font
_HMG_SYSDATA \[ 423 \] := Nil ;; // size
_HMG_SYSDATA \[ 412 \] := .f. ;; //bold
_HMG_SYSDATA \[ 413 \] := .f. ;; // italic
_HMG_SYSDATA \[ 415 \] := .f. ;; // underline
_HMG_SYSDATA \[ 424 \] := Nil ;; //tooltip
_HMG_SYSDATA \[ 457 \] := Nil ;; // backcolor
_HMG_SYSDATA \[ 458 \] := Nil ;; // fontcolor
_HMG_SYSDATA \[ 442 \] := Nil ;; // maxlength
_HMG_SYSDATA \[ 475 \] := .f. ;; //upper
_HMG_SYSDATA \[ 476 \] := .f. ;; //lower
_HMG_SYSDATA \[ 477 \] := .f. ;; // numeric
_HMG_SYSDATA \[ 426 \] := Nil ;; // gotfocus
_HMG_SYSDATA \[ 427 \] := Nil ;; //lostfocus
_HMG_SYSDATA \[ 437 \] := Nil ;; //enter
_HMG_SYSDATA \[ 440 \] := .f. ;; //rightalign
_HMG_SYSDATA \[ 428 \] := .t. ;; //tabstop
_HMG_SYSDATA \[ 429 \] := Nil ;; // helpid
_HMG_SYSDATA \[ 436 \] := Nil ;; // items
_HMG_SYSDATA \[ 445 \] := Nil ;; // headers
_HMG_SYSDATA \[ 446 \] := Nil ;; // widths
_HMG_SYSDATA \[ 464 \] := .f. // anywhere search
#xcommand END COMBOSEARCHGRID;
=>;
_DefineComboSearchGrid(;
_HMG_SYSDATA \[ 416 \],; //name
_HMG_SYSDATA \[ 417 \],; //parent
_HMG_SYSDATA \[ 432 \],; //col
_HMG_SYSDATA \[ 431 \],; //row
_HMG_SYSDATA \[ 420 \],; //width
_HMG_SYSDATA \[ 421 \],; //height
_HMG_SYSDATA \[ 434 \],; //value
_HMG_SYSDATA \[ 422 \],; //fontname
_HMG_SYSDATA \[ 423 \],; //fontsize
_HMG_SYSDATA \[ 424 \],; //tooltip
_HMG_SYSDATA \[ 442 \],; //maxlength
_HMG_SYSDATA \[ 475 \],; //upper
_HMG_SYSDATA \[ 476 \],; //lower
_HMG_SYSDATA \[ 477 \],; //numeric
_HMG_SYSDATA \[ 427 \],; //lostfocus
_HMG_SYSDATA \[ 426 \],; //gotfocus
_HMG_SYSDATA \[ 437 \],; //enter
_HMG_SYSDATA \[ 440 \],; //rightalign
_HMG_SYSDATA \[ 429 \],; //helpid
_HMG_SYSDATA \[ 412 \],; //bold
_HMG_SYSDATA \[ 413 \] , ; //italic
_HMG_SYSDATA \[ 415 \],; //underline
_HMG_SYSDATA \[ 457 \] , ; //backcolor
_HMG_SYSDATA \[ 458 \] , ;// fontcolor
_HMG_SYSDATA \[ 428 \] ,; //tabstop
_HMG_SYSDATA \[ 436 \] ,; // aitems
_HMG_SYSDATA \[ 464 \], ; // anywhere search
_HMG_SYSDATA \[ 445 \], ; // headers
_HMG_SYSDATA \[ 446 \] ; // widths
)
function main
local aArray := {{"Rathinagiri","Sivakasi"},{"Raman","Madurai"},{"Rajan","Chennai"},{"Rajkumar","Delhi"}}
define window x at 0,0 width 500 height 400 main
define label namelabel
row 10
col 10
width 100
value "Name"
end label
define combosearchgrid names
row 10
col 110
width 300
items aArray
headers {"Name","City"}
widths {200,80}
end combosearchgrid
define button ok
row 40
col 10
width 80
caption "Ok"
action msginfo("Just a button")
end button
end window
x.center
x.activate
return nil
PROC _DefineComboSearchGrid( cCSBoxName,;
cCSBoxParent,;
cCSBoxCol,;
cCSBoxRow,;
cCSBoxWidth,;
cCSBoxHeight,;
cCSBoxValue,;
cFontName,;
nFontSize,;
cToolTip,;
nMaxLenght,;
lUpper,;
lLower,;
lNumeric,;
bLostFocus,;
bGotFocus,;
bEnter,;
lRightAlign,;
nHelpId,;
lBold,;
lItalic,;
lUnderline,;
aBackColor,;
aFontColor,;
lNoTabStop,;
aArray,;
lAnyWhere,;
aHeaders,;
aWidths )
LOCAL cParentName := ''
DEFAULT cCSBoxWidth := 120
DEFAULT cCSBoxHeight := 24
DEFAULT cCSBoxValue := ""
DEFAULT bGotFocus := ""
DEFAULT bLostFocus := ""
DEFAULT nMaxLenght := 255
DEFAULT lUpper := .F.
DEFAULT lLower := .F.
DEFAULT lNumeric := .F.
DEFAULT bEnter := ""
DEFAULT lAnyWhere := .f.
IF _HMG_SYSDATA [ 264 ] = .T. // _HMG_BeginWindowActive
cParentName := _HMG_SYSDATA [ 223 ] // _HMG_ActiveFormName
ELSE
cParentName := cCSBoxParent
ENDIF
_DefineTextBox( cCSBoxName,;
cCSBoxParent,;
cCSBoxcol,;
cCSBoxRow,;
cCSBoxWidth,;
cCSBoxheight,;
cCSBoxValue,;
cFontName,;
nFontSize,;
cToolTip,;
nMaxLenght,;
lUpper,;
lLower,;
lNumeric,;
.f.,;
bLostFocus,;
bGotFocus,;
{||CreateCSBoxGrid( cParentName, cCSBoxName, aArray, cCSBoxRow, cCSBoxCol,lAnyWhere,aHeaders,aWidths)},;
bEnter,;
lRightAlign,;
nHelpId,;
.f.,;
lBold,;
lItalic,;
lUnderline,;
.f.,;
,;
aBackColor,;
aFontColor,;
.f.,;
iif(lNoTabStop,.f.,.t.);
)
RETURN // _DefineComboSearchGrid()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
STATIC PROC CreateCSBoxGrid( cParentName, cCSBoxName, aitems, cCSBoxRow, cCSBoxCol,lAnyWhere, aHeaders, aWidths )
LOCAL nFormRow := thisWindow.row
LOCAL nFormCol := thisWindow.col
LOCAL nControlRow := this.row
LOCAL nControlCol := this.col
LOCAL nControlWidth := this.width
LOCAL nControlHeight := this.height
LOCAL cCurValue := this.value
LOCAL aResults := {}
LOCAL nContIndx := GetControlIndex( this.name, thiswindow.name )
LOCAL result := 0
LOCAL nItemNo := 0
LOCAL nListBoxHeight := 0
LOCAL caret := this.CaretPos
LOCAL cCSBxName := 'frm' + cCSBoxName
IF !EMPTY(cCurValue)
IF _HMG_SYSDATA [ 23, nContIndx ] # -1 // _HMG_aControlContainerRow
nControlRow += _HMG_SYSDATA [ 23, nContIndx ] // _HMG_aControlContainerRow
nControlCol += _HMG_SYSDATA [ 24, nContIndx ] // _HMG_aControlContainerCol
ENDIF
FOR nItemNo := 1 TO LEN(aitems)
IF UPPER( aitems[ nItemNo,1 ] ) == UPPER( cCurValue )
EXIT // item selected already
ENDIF
IF UPPER( LEFT( aitems[ nItemNo,1 ], LEN( cCurValue ))) == UPPER(cCurValue)
AADD( aResults, aitems[ nItemNo ] )
ENDIF
NEXT nItemNo
IF LEN( aResults ) > 0
nListBoxHeight := MAX(MIN((LEN(aResults) * 16)+60,thiswindow.height - nControlRow - nControlHeight-10),40)
DEFINE WINDOW &cCSBxName ;
AT nFormRow+nControlRow+20, nFormCol+nControlCol ;
WIDTH nControlWidth+6 ;
HEIGHT nListBoxHeight+nControlHeight ;
TITLE '' ;
MODAL ;
NOCAPTION ;
NOSIZE
ON KEY UP OF This.Window ACTION _CSGridDoUpKey()
ON KEY DOWN OF This.Window ACTION _CSGridDoDownKey()
ON KEY ESCAPE OF This.Window ACTION _CSGridDoEscKey(cParentName, cCSBoxName)
DEFINE TEXTBOX _cstext
ROW 3
COL 3
WIDTH nControlWidth
HEIGHT nControlHeight
FONTNAME this.fontname
FONTSIZE this.Fontsize
TOOLTIP this.tooltip
FONTBOLD this.fontbold
FONTITALIC this.fontitalic
FONTUNDERLINE this.fontunderline
BACKCOLOR this.backcolor
FONTCOLOR this.fontcolor
ON CHANGE _CSGridTextChanged( cParentName, aitems, cCSBoxName, lAnyWhere )
ON ENTER _CSGridItemSelected( cParentName, aitems, cCSBoxName )
END TEXTBOX
DEFINE Grid _cslist
ROW nControlHeight+3
COL 3
WIDTH nControlWidth
HEIGHT nListBoxHeight + 25
ITEMS aResults
ON DBLCLICK _CSGridItemSelected( cParentName, aitems, cCSBoxName )
VALUE 1
HEADERS aHeaders
WIDTHS aWidths
END Grid
END WINDOW
SetProperty( cCSBxName, '_cstext', "VALUE", cCurValue )
SetProperty( cCSBxName, '_cstext', "CaretPos", caret )
ACTIVATE WINDOW &cCSBxName
ENDIF
ENDIF
RETURN // CreateCSBoxGrid()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
STATIC PROC _CSGridTextChanged( cParentName, aItems, cTxBName, lAnyWhere )
LOCAL cCurValue := GetProperty( ThisWindow.Name, '_cstext', "VALUE" )
LOCAL aResults := {}
LOCAL nItemNo := 0
LOCAL nListBoxHeight := 0
LOCAL nParentHeight := GetProperty(cParentName,"HEIGHT")
LOCAL nParentRow := GetProperty(cParentName,"ROW")
DoMethod( ThisWindow.Name, "_csList", 'DeleteAllItems' )
FOR nItemNo := 1 TO LEN(aitems)
IF lAnyWhere
IF AT(UPPER(cCurValue),UPPER(aItems[nItemNo,1])) > 0
AADD(aResults,aitems[ nItemNo ])
ENDIF
ELSE
IF UPPER( LEFT( aitems[ nItemNo,1 ], LEN(cCurValue))) == UPPER(cCurValue)
AADD(aResults,aitems[ nItemNo ])
ENDIF
ENDIF
NEXT nItemNo
IF LEN(aResults) > 0
FOR nItemNo := 1 TO LEN(aResults)
DoMethod( ThisWindow.Name, "_csList", 'AddItem', aResults[ nItemNo ] )
NEXT i
SetProperty( ThisWindow.Name, "_csList", "VALUE", 1 )
ENDIF
nListBoxHeight := MAX(MIN((LEN(aResults) * 16)+6,(nParentHeight + nParentRow - ;
GetProperty( ThisWindow.Name, 'ROW' ) - ;
GetProperty( ThisWindow.Name, "_csText", 'ROW' ) - ;
GetProperty( ThisWindow.Name, "_csText", 'HEIGHT' ) - 14)), 40)
SetProperty( ThisWindow.Name, "_csList", "HEIGHT", nListBoxHeight +25)
SetProperty( ThisWindow.Name, "HEIGHT", nListBoxHeight + 25+ GetProperty( ThisWindow.Name, '_cstext', "HEIGHT" ) )
RETURN // _CSGridTextChanged()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
STATIC PROC _CSGridItemSelected( cParentName, aitems, cTxBName )
local cFormName := ThisWindow.Name
local aLine := {}
if GetProperty( ThisWindow.Name, "_csList", "VALUE" ) > 0
nListValue := GetProperty( ThisWindow.Name, '_csList', "VALUE" )
aLine := GetProperty( ThisWindow.Name, '_csList', "ITEM", nListValue )
cListItem := aLine[1]
SetProperty( cParentName, cTxBName, "VALUE", cListItem )
SetProperty(cParentName,cTxBName,"CARETPOS",;
LEN( GetProperty( cFormName, '_csList', "ITEM",;
GetProperty( cFormName, '_csList', "VALUE" ) ) ) )
DoMethod( ThisWindow.Name, "Release" )
ENDIF
RETURN // _CSGridItemSelected()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
STATIC PROC _CSGridDoUpKey()
IF GetProperty( ThisWindow.Name, '_csList', "ItemCount" ) > 0 .AND. ;
GetProperty( ThisWindow.Name, '_csList', "VALUE" ) > 1
SetProperty( ThisWindow.Name, '_csList', "VALUE", GetProperty( ThisWindow.Name, '_csList', "VALUE" ) - 1 )
ENDIF
RETURN // _CSGridDoUpKey()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
STATIC PROC _CSGridDoDownKey()
IF GetProperty( ThisWindow.Name, '_csList', "ItemCount" ) > 0 .AND. ;
GetProperty( ThisWindow.Name, '_csList', "VALUE" ) < ;
GetProperty( ThisWindow.Name, '_csList', "ItemCount" )
SetProperty( ThisWindow.Name, '_csList', "VALUE", GetProperty( ThisWindow.Name, '_csList', "VALUE" ) + 1 )
ENDIF
RETURN // _CSGridDoDownKey()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
STATIC PROC _CSGridDoEscKey(cParentName, cCSBoxName)
SetProperty( ThisWindow.Name, '_csText', "VALUE",'')
SetProperty( cParentName, cCSBoxName, "VALUE",'')
DoMethod( ThisWindow.Name, "Release" )
RETURN // _CSGridDoEscKey()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._
Everything works fine. The only problem is we can not the blue background color as in listbox even though the grid item is selected. The reason is, listbox is by default having blue color for the selected item both in focus state and non-focus state. Where as, grids by default make it grey when not in focus.
If we can get a work around using dynamicbackcolor, this would also be solved, I think.