jeudi 25 mars 2010

recherche dans une grille

$APPTYPE GUI
$typecheck on

$include "include/rapidq2.inc"

DECLARE SUB cherche_click
DECLARE SUB ouvre_click
DECLARE SUB remplir_combobox
DECLARE SUB Quit_click
DECLARE SUB efface_grille


CREATE Form AS QFORM
Caption = "test de recherche"
Width = 728
Height = 394
Center
CREATE mainmenu as QMAINMENU
CREATE men_file as qmenuitem
caption = "Fichier"
create mnu_file_ouvre as qmenuitem
caption = "Ouvrir"
onclick = ouvre_click
end create
create mnu_file_brek as qmenuitem
caption = "-"
end create
create mnu_file_quit as qmenuitem
caption = "Quitter"
onclick = Quit_click
end create
end create
END CREATE
CREATE Panel1 AS QPANEL
Width = 720
Align = 1
visible = false
CREATE Label1 AS QLABEL
Caption = "Chercher :"
Left = 16
Top = 12
Width = 64
Transparent = 1
END CREATE
CREATE Label2 AS QLABEL
Caption = "Dans :"
Left = 200
Top = 12
Transparent = 1
END CREATE
CREATE Edit1 AS QEDIT
Text = "texte a chercher"
Left = 72
Top = 8
END CREATE
CREATE ComboBox1 AS QCOMBOBOX
AddItems "reprendre les entête de la grille"
Text = "ComboBox1"
Left = 240
Top = 8
END CREATE
CREATE BTN1 AS QBUTTON
Caption = "Chercher"
Left = 400
Top = 8
Height = 21
OnClick = cherche_click
END CREATE
END CREATE
CREATE Grille AS QSTRINGGRID
'Left = 0
'Top = 41
'Height = 320
'Width = 720
Align = 5
DefaultColWidth = 80
DefaultRowHeight = 16
FixedCols = 0
ColCount = 3
editormode=true
addoptions(7,10,13)
visible = false
END CREATE
END CREATE

Form.ShowModal

SUB cherche_click

if edit1.text = "" then
showmessage "Aucun texte à chercher !"
exit sub
end if

if combobox1.text = "" then
showmessage "Aucune colonne de recherche déterminée !"
exit sub
end if

' deux option celle ci (plus facile)
' ou celle avec INSTR

DIM ligne_grille as integer
showmessage "chercher le texte " & chr$(34) & edit1.text & chr$(34) & " dans la colonne intitulée : " & grille.cell(val(combobox1.text),0)
for ligne_grille = 1 to grille.rowcount-1
if grille.cell(val(combobox1.text),ligne_grille)= edit1.text then
showmessage "Le texte à été trouvé !" &chr$(10) & "Dans la ligne n° : " &chr$(34) & str$(ligne_grille) & chr$(34)
grille.col = val(combobox1.text)
grille.row = ligne_grille
'grille.selectedcell(combobox1.text)
exit sub
end if
next
showmessage "Le terme " & chr$(34) & edit1.text & " Ne figure pas dans cette colonne."
END SUB


SUB ouvre_click
DIM nombre_ligne as integer
dim opendial as qopendialog

opendial.filter = "*.csv et *.ini |*.csv;*.ini|Tous (*.*)|*.*"
opendial.filterindex = 0
opendial.initialdir = application.path

if opendial.execute then
call efface_grille
grille.loadfromfile(opendial.filename,0,0,99999)
Showmessage "ouvrir une grille"
combobox1.clear
call remplir_combobox
end if
panel1.visible = true
grille.visible = true
END SUB

sub remplir_combobox
dim i as integer
for I = 0 to grille.colcount-1
combobox1.additems(grille.cell(I,0))
next
end sub

sub effacer_grille
dim lign as integer, colo as integer
for colo = 0 to grille.colcount-1
for lign = 0 to grille.rowcount-1
grille.cell(colo,lign)=""
next
next
end sub

SUB Quit_click
application.terminate
END SUB