RE:Buscar digitando los primeros caracteres
Saludos, te envío un objeto que lo baje de la web.
Para usarlo colocas el siguiente código en el evento open:
sle_busca.initdw( dw_search, 'nombrecolumna' )
Este código lo copias en el block de notas lo guardas con un nombre, por ejemplo sle_busca.sru y luego lo importas a tu librería.
$PBExportHeader$sle_busca.sru
$PBExportComments$Busca el texto que se va ingresando en este objeto en un campo de tipo string de un DW y se coloca en la fila encontrada.
forward
global type sle_busca from singlelineedit
end type
end forward
global type sle_busca from singlelineedit
integer width = 411
integer height = 84
integer taborder = 1
integer textsize = -8
integer weight = 400
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
boolean autohscroll = false
borderstyle borderstyle = stylelowered!
event key_press pbm_keydown
end type
global sle_busca sle_busca
type variables
PRIVATE:
long il_selectedrow
string is_filter
Long il_parm
String is_parm, is_tipodato
Integer ii_campo
datawindow idw_Search
string is_ColName
boolean ib_Init = FALSE
end variables
forward prototypes
public function boolean initdw (ref datawindow adw_search, string as_colname)
end prototypes
event key_press;int li_movement
long ll_row
If KeyDown (keyUparrow!) then
li_movement = -1
End If
If KeyDown (keyDownarrow!) then
li_movement = 1
End If
If li_movement <> 0 Then
idw_search.SetRedraw(False)
ll_row = idw_search.GetSelectedRow(0)
ll_row = ll_row + li_movement
If ll_row < 1 or ll_row > idw_search.RowCount( ) Then
Beep(1)
Return
End If
idw_search.selectrow(0,False)
idw_search.SelectRow(ll_row , True)
idw_search.ScrollToRow (ll_row)
This.text = idw_search.GetItemString(ll_row , is_colname)
is_filter = This.text
il_selectedrow = ll_row
idw_search.SetRedraw(True)
This.SelectText(len(This.text) + 1,0)
message.processed = true
Return
End If
string ls_character
long ll_found_row
int li_num_chars
ls_character = Char(message.wordparm)
/* Descomentar esto para que controle que busque solo letras
If ls_character <> " " Then
If (Lower(ls_character) < "a" or Lower(ls_character) > "z") and ls_character <> Char(8) Then
message.processed = true
Return
End If
End If */
If message.wordparm = 8 then
li_num_chars = Len(is_filter)
If li_num_chars > 0 then is_filter = Left(is_filter, li_num_chars -1)
else
is_filter = is_filter + ls_character
end if
If Len(is_filter) > 0 Then
ll_found_row = idw_search.Find("Lower("+is_colname+") LIKE ~"" + Lower(is_filter) + "%~"",1, 99999)
If ll_found_row > 0 then
idw_search.SetRedraw(FALSE)
idw_search.SelectRow(0, FALSE)
idw_search.ScrollToRow(ll_found_row)
idw_search.SelectRow(ll_found_row, TRUE)
idw_search.SetRedraw(TRUE)
Else
Beep(1)
li_num_chars = Len(is_filter)
If li_num_chars > 0 Then is_filter = Left(is_filter, li_num_chars -1)
message.processed = true
End If
Else
idw_search.SelectRow(0, FALSE)
End If
end event
public function boolean initdw (ref datawindow adw_search, string as_colname);/********************************************************************
initdw
<DESC> Set a datawindow instance variable with the datawindow
passed to this method. Also, set the column that in which
the developer wants the search to be performed. </DESC>
<RETURN> boolean:
<LI> TRUE, Initialized OK
<LI> FALSE, Initialize failed </RETURN>
<ACCESS> Public
<ARGS> adw_Search: Datawindow in which the search is to be
performed
as_ColName: Column name to search for the entered value.
</ARGS>
<USAGE> If sle_find.initdw( dw_search, 'KeyCol' ) Then ...
</USAGE>
********************************************************************/
String ls_ColType
If as_ColName = "" Then RETURN FALSE
idw_Search = adw_Search
is_ColName = as_ColName
ls_Coltype = idw_Search.Describe(is_ColName+".coltype")
If Lower( Left( ls_Coltype, 4 ) ) <> "char" Then RETURN FALSE
ib_Init = True
RETURN TRUE
end function
on sle_busca.create
end on
on sle_busca.destroy
end on