[RESOLU]Aide a la saisie

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
pierre003
Messages : 60
Inscription : ven. 27/mai/2016 8:27
Localisation : 03

[RESOLU]Aide a la saisie

Message par pierre003 »

Bonjour a toutes et a tous.
C’est encore moi, j’ai bricolé ce bout programme pour aider a la saisie, je ne sais pas comment cela s’appelle mais ont en voit dans beaucoup de programmes, on tape les premiers caractères et il affiche les données qui commence par ces caractères.
Il n’est surement pas optimisé, mais je débute dans PureBasic.
Voila mon problème :
Je souhaiterai lorsque je clique sur une donnée qui est dans la ListIcon « AfficheNoms », elle s’affiche dans le GadgetText « FourTout »
Merci pour votre patience et pour vos réponses.
Pierre

Code : Tout sélectionner

EnableExplicit
Enumeration Window
  #MainForm
EndEnumeration

Enumeration Gadget
  #Quitte
  #EntreNom
  #AfficheNoms
  #FoureTout
EndEnumeration

Global Window_0
Global a.i
Global Dim Noms.s(10000)
Global NbNoms.i
Global NomCherche.s
Global i.l

Declare Start()
Declare Exit()
Declare CaptureTexte()
Declare RechercheNoms()
Declare ChargeData()

ChargeData()
Start()

Procedure Start()
     OpenWindow(#MainForm, 0, 0, 1000, 700, "Premiere fenêtre", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget )       
     ListIconGadget(#AfficheNoms, 10, 20, 280, 300, "Column 1", 275,#PB_ListIcon_GridLines )
     StringGadget(#EntreNom, 300, 20, 100, 22, "",#PB_String_UpperCase )
     StringGadget(#FoureTout, 450, 20, 100, 22, "FoureTout")
    ButtonGadget(#Quitte, 730, 100, 120, 40, "Quitte")
    BindGadgetEvent(#Quitte, @Exit())
    SetActiveGadget(#EntreNom)
    BindGadgetEvent(#EntreNom,@CaptureTexte())
    Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure CaptureTexte()
   Define LgRech.w
  Select EventType()
      Case #PB_EventType_Change       
        NomCherche=GetGadgetText(#EntreNom)
        LgRech=Len(NomCherche)
        ClearGadgetItems(#AfficheNoms) 
        For i=1 To NbNoms
            If Left(Noms(i),LgRech) = NomCherche
                AddGadgetItem(#AfficheNoms,-1,Noms(i))
             EndIf
         Next
  EndSelect
EndProcedure

; Pour test
Procedure ChargeData()
    OpenCryptRandom()
    For i=1 To 9900
        For a=1 To 10
            Noms(i)+ Chr( CryptRandom(26)+65)
        Next
    Next
    NbNoms=i
EndProcedure

Procedure Exit()
    End
EndProcedure
Dernière modification par pierre003 le jeu. 02/août/2018 7:20, modifié 1 fois.
Toshiba satellite Windows 7 64bits
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Aide a la saisie

Message par microdevweb »

Si j'ai bien compris ta question, voici une solution parmi d'autres.
J'ai modifié légèrement ton code, j'ai ajouté ;MCW au code que j'ai ajouté

Code : Tout sélectionner

EnableExplicit
Enumeration Window
  #MainForm
EndEnumeration

Enumeration Gadget
  #Quitte
  #EntreNom
  #AfficheNoms
  #FoureTout
EndEnumeration

Global Window_0
Global a.i
Global Dim Noms.s(10000)
Global NbNoms.i
Global NomCherche.s
Global i.l

Declare Start()
Declare Exit()
Declare CaptureTexte()
Declare RechercheNoms()
Declare ChargeData()
Declare displayListItem()

ChargeData()
Start()

Procedure Start()
  OpenWindow(#MainForm, 0, 0, 1000, 700, "Premiere fenêtre", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget )       
  ListIconGadget(#AfficheNoms, 10, 20, 280, 300, "Column 1", 275,#PB_ListIcon_GridLines )
  StringGadget(#EntreNom, 300, 20, 100, 22, "",#PB_String_UpperCase )
  StringGadget(#FoureTout, 450, 20, 100, 22, "FoureTout")
  ButtonGadget(#Quitte, 730, 100, 120, 40, "Quitte")
  BindGadgetEvent(#Quitte, @Exit())
  SetActiveGadget(#EntreNom)
  BindGadgetEvent(#EntreNom,@CaptureTexte())
  BindGadgetEvent(#AfficheNoms,@displayListItem()) ;MCW
  Repeat : WaitWindowEvent() : ForEver
EndProcedure

Procedure CaptureTexte()
  Define LgRech.w,id
  Select EventType()
    Case #PB_EventType_Change       
      NomCherche=GetGadgetText(#EntreNom)
      LgRech=Len(NomCherche)
      ClearGadgetItems(#AfficheNoms) 
      For i=1 To NbNoms
        If Left(Noms(i),LgRech) = NomCherche
          AddGadgetItem(#AfficheNoms,-1,Noms(i))
          ; MCW mémorise l'id du nom
          SetGadgetItemData(#AfficheNoms,id,i)
          id + 1  ; MCW  incrrémente l'id
        EndIf
      Next
  EndSelect
EndProcedure

; Pour test
Procedure ChargeData()
  OpenCryptRandom()
  For i=1 To 9900
    For a=1 To 10
      Noms(i)+ Chr( CryptRandom(26)+65)
    Next
  Next
  NbNoms=i
EndProcedure

; MCW
Procedure displayListItem()
  Protected idSelected = GetGadgetState(#AfficheNoms)
  If idSelected > -1
    SetGadgetText(#FoureTout,Noms(GetGadgetItemData(#AfficheNoms,idSelected)))
  EndIf
EndProcedure

Procedure Exit()
  End
EndProcedure
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
pierre003
Messages : 60
Inscription : ven. 27/mai/2016 8:27
Localisation : 03

Re: Aide a la saisie

Message par pierre003 »

microdevweb a écrit :Si j'ai bien compris ta question, voici une solution parmi d'autres.
J'ai modifié légèrement ton code, j'ai ajouté ;MCW au code que j'ai ajouté
Merci microdevweb, ça marche super.
Comme ne n’ai pas encore terminé mon projet je reviendrais surement pour tous vous ennuyer avec mes problèmes. :oops:
Pierre
Toshiba satellite Windows 7 64bits
Marc56
Messages : 2147
Inscription : sam. 08/févr./2014 15:19

Re: Aide a la saisie

Message par Marc56 »

j’ai bricolé ce bout programme pour aider a la saisie, je ne sais pas comment cela s’appelle...
autocomplétion :wink:
pierre003
Messages : 60
Inscription : ven. 27/mai/2016 8:27
Localisation : 03

Re: Aide a la saisie

Message par pierre003 »

Marc56 a écrit :
j’ai bricolé ce bout programme pour aider a la saisie, je ne sais pas comment cela s’appelle...
autocomplétion :wink:
Merci Marc56, maintenant tu le dis ça me parle, je savais que c’était auto mais la suite :?: :?:
Toshiba satellite Windows 7 64bits
boby
Messages : 261
Inscription : jeu. 07/juin/2007 22:54

Re: Aide a la saisie

Message par boby »

C'est du bricolage... mais ça "marche"

Code : Tout sélectionner

Global str, txt, Lst, NewList text.s()
Declare totocomplettagement()
Declare Shortcut()
Declare Close()
Declare bourage()
Declare complette()
Declare CompletteEvent()
If OpenWindow(0,0,0,200,200,"totocompletion",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  str= StringGadget(#PB_Any,10,10,80,20,"",#PB_String_UpperCase )
  txt = TextGadget(#PB_Any,100,10,80,20,"Four tout")
  SetActiveGadget(str)
  AddKeyboardShortcut(0,#PB_Shortcut_Down,1)
  AddKeyboardShortcut(0,#PB_Shortcut_Up,2)
  AddKeyboardShortcut(0,#PB_Shortcut_Return,3)
  BindEvent(#PB_Event_CloseWindow,@Close())
  BindEvent(#PB_Event_Menu,@Shortcut())
  BindGadgetEvent(str,@totocomplettagement())
  bourage()
EndIf
Repeat : WaitWindowEvent() : ForEver

Procedure Close()
  End
EndProcedure

Procedure totocomplettagement()
  Protected text$ = GetGadgetText(str)
  If EventType() = #PB_EventType_Change
    If Not IsWindow(1)
      OpenWindow(1,WindowX(0)+15,WindowY(0)+35+GetSystemMetrics_(#SM_CYMENU),80,100,"",#PB_Window_BorderLess,WindowID(0))
      lst= ListViewGadget(#PB_Any,0,0,80,100)
      BindGadgetEvent(lst,@CompletteEvent())
      SetActiveWindow(0)
    Else
      ClearGadgetItems(lst)
    EndIf
    If text$ = ""
      If IsWindow(1)
        UnbindGadgetEvent(lst,@CompletteEvent())
        CloseWindow(1)
      EndIf
    Else
      ForEach text()
        If Left(text(),Len(text$)) = text$
          AddGadgetItem(lst,-1,text())
        EndIf
      Next
    EndIf
  EndIf
EndProcedure

Procedure Shortcut()
  If IsWindow(1)
    Select EventMenu()
      Case 1
        SetGadgetState(lst,GetGadgetState(lst)+1)
      Case 2
        If GetGadgetState(lst)
          SetGadgetState(lst,GetGadgetState(lst)-1)
        EndIf
      Case 3
        complette()
    EndSelect
  EndIf
EndProcedure

Procedure bourage()
  Protected I, a, txt$
  OpenCryptRandom()
  For i=1 To 9900
    For a=1 To 10
      txt$+ Chr( CryptRandom(26)+65)
    Next
    AddElement(text())
    text() = txt$
    txt$ = ""
  Next
EndProcedure
Procedure CompletteEvent()
  If EventType() = #PB_EventType_LeftClick
    complette()
  EndIf
EndProcedure
Procedure complette()
  SetGadgetText(txt,GetGadgetText(lst))
  UnbindGadgetEvent(lst,@CompletteEvent())
  CloseWindow(1)
EndProcedure
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Aide a la saisie

Message par Kwai chang caine »

Code : Tout sélectionner

complettagement
:lol:
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Répondre