IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants FMX Delphi Discussion :

Savoir si une liste (Listbox ou ListView) est filtrée


Sujet :

Composants FMX Delphi

  1. #1
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 029
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 029
    Points : 40 928
    Points
    40 928
    Billets dans le blog
    62
    Par défaut Savoir si une liste (Listbox ou ListView) est filtrée
    Bonjour,

    presque tout est dans le titre. Suite à cette FAQ je me suis aperçu qu'une liste ne se triait pas (nuances : plus avec Rio, pas avec Sidney) si elle était filtrée par utilisation de la recherche d'où ma question.

    ci-dessous les sources (code et forme)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    unit UTestSortList;
     
    interface
     
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
      Data.Bind.GenData, Data.Bind.EngExt, Fmx.Bind.DBEngExt, System.Rtti,
      System.Bindings.Outputs, Fmx.Bind.Editors, FMX.Objects, Data.Bind.Components,
      FMX.Edit, FMX.SearchBox, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts,
      FMX.ListBox, Data.Bind.ObjectScope;
     
    type
      TForm1 = class(TForm)
        PrototypeBindSource1: TPrototypeBindSource;
        ListBox1: TListBox;
        btnSortbyName: TButton;
        btnSortByBonus: TButton;
        SearchBox1: TSearchBox;
        BindingsList1: TBindingsList;
        LinkListControlToField1: TLinkListControlToField;
        PathSortN: TPath;
        PathSortB: TPath;
        procedure btnSortbyNameClick(Sender: TObject);
        procedure btnSortByBonusClick(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.fmx}
     
    uses System.Math;
     
    procedure TForm1.btnSortByBonusClick(Sender: TObject);
    var Compare : TFMXObjectSortCompare;
    begin
    {TODO -oOwner -cGeneral : tester si la liste est filtrée}
     PathSortN.Visible:=False;
     btnSortByBonus.Tag:=IfThen(btnSortByBonus.Tag=0,1,0);
     PathSortB.RotationAngle:=180*btnSortByBonus.Tag;
     PathSortB.Visible:=True;
     ListBox1.Sorted:=False;
     Compare:=function(Item1, Item2: TFmxObject): Integer
      var n1,n2 : Single;
      begin
        n1:=StrToFloatDef(TListBoxItem(Item1).ItemData.Detail,0);
        n2:=StrToFloatDef(TListBoxItem(Item2).ItemData.Detail,0);
        if n1=n2 then Result:=0
        else begin
          if n2>n1 then Result := 1
                   else Result := -1;
        end;
        if btnSortByBonus.Tag=1 then Result:=Result*-1;
      end;
     ListBox1.Sort(Compare);
     ListBox1.RealignContent;
    end;
     
    procedure TForm1.btnSortbyNameClick(Sender: TObject);
    var Compare : TFMXObjectSortCompare;
    begin
    {TODO -oOwner -cGeneral : tester si la liste est filtrée}
    // si filtrée exit;
     PathSortB.Visible:=False;
     btnSortByName.Tag:=IfThen(btnSortByName.Tag=0,1,0);
     PathSortN.RotationAngle:=180*btnSortByName.Tag;
     PathSortN.Visible:=True;
     ListBox1.Sorted:=False;
     Compare:=function(Item1, Item2: TFmxObject): Integer
      begin
        result:=CompareText(TListBoxItem(Item1).text,TListBoxItem(Item2).text);
        if btnSortByName.Tag=1 then Result:=Result*-1;
      end;
     ListBox1.Sort(Compare);
     ListBox1.RealignContent;
    end;
     
    end.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = ' ListBox Sort and Search'
      ClientHeight = 433
      ClientWidth = 383
      FormFactor.Width = 320
      FormFactor.Height = 480
      FormFactor.Devices = [Desktop]
      DesignerMasterStyle = 0
      object ListBox1: TListBox
        Position.X = 8.000000000000000000
        Position.Y = 72.000000000000000000
        Size.Width = 321.000000000000000000
        Size.Height = 297.000000000000000000
        Size.PlatformDefault = False
        DisableFocusEffect = True
        ItemIndex = 0
        Items.Strings = (
          'Mary Harris'
          'James Garcia'
          'Paul Davis'
          'Adam Brown'
          'Susan Sanchez'
          'Steve Moore'
          'Donna Martin'
          'Mark Anderson'
          'Michelle Smith'
          'Christine Jones')
        DefaultItemStyles.ItemStyle = 'listboxitemrightdetail'
        DefaultItemStyles.GroupHeaderStyle = ''
        DefaultItemStyles.GroupFooterStyle = ''
        Viewport.Width = 317.000000000000000000
        Viewport.Height = 271.000000000000000000
        object SearchBox1: TSearchBox
          Touch.InteractiveGestures = [LongTap, DoubleTap]
          Align = Top
          Size.Width = 317.000000000000000000
          Size.Height = 22.000000000000000000
          Size.PlatformDefault = False
        end
      end
      object btnSortbyName: TButton
        Position.X = 8.000000000000000000
        Position.Y = 384.000000000000000000
        Size.Width = 97.000000000000000000
        Size.Height = 33.000000000000000000
        Size.PlatformDefault = False
        Text = 'Sort by Name'
        OnClick = btnSortbyNameClick
      end
      object btnSortByBonus: TButton
        Position.X = 208.000000000000000000
        Position.Y = 384.000000000000000000
        Size.Width = 97.000000000000000000
        Size.Height = 33.000000000000000000
        Size.PlatformDefault = False
        Text = 'Sort by Bonus'
        OnClick = btnSortByBonusClick
      end
      object PathSortN: TPath
        Data.Path = {
          04000000000000000000803F0000A841010000000000B8410000A84101000000
          0000404100000040030000000000803F0000A841}
        Fill.Color = claBlack
        HitTest = False
        Position.X = 108.000000000000000000
        Position.Y = 388.000000000000000000
        Size.Width = 25.000000000000000000
        Size.Height = 25.000000000000000000
        Size.PlatformDefault = False
        Stroke.Kind = None
        Visible = False
      end
      object PathSortB: TPath
        Data.Path = {
          04000000000000000000803F0000A841010000000000B8410000A84101000000
          0000404100000040030000000000803F0000A841}
        Fill.Color = claBlack
        HitTest = False
        Position.X = 308.000000000000000000
        Position.Y = 388.000000000000000000
        Size.Width = 25.000000000000000000
        Size.Height = 25.000000000000000000
        Size.PlatformDefault = False
        Stroke.Kind = None
        Visible = False
      end
      object PrototypeBindSource1: TPrototypeBindSource
        AutoActivate = True
        AutoPost = False
        FieldDefs = <
          item
            Name = 'CName'
            Generator = 'ContactNames'
            Options = [optShuffle]
            ReadOnly = False
          end
          item
            Name = 'CBonus'
            FieldType = ftCurrency
            Generator = 'Currency'
            ReadOnly = False
          end>
        ScopeMappings = <>
        Left = 144
        Top = 8
      end
      object BindingsList1: TBindingsList
        Methods = <>
        OutputConverters = <>
        Left = 28
        Top = 5
        object LinkListControlToField1: TLinkListControlToField
          Category = 'Liaisons rapides'
          DataSource = PrototypeBindSource1
          FieldName = 'CName'
          Control = ListBox1
          FillExpressions = <
            item
              SourceMemberName = 'CBonus'
              ControlMemberName = 'Detail'
            end>
          FillHeaderExpressions = <>
          FillBreakGroups = <>
        end
      end
    end
    J'ai tenté la piste nombre d'items de la liste (-1 pour l'item de recherche) différent de nombre d'enregistrements mais, s'agissant d'un TProtypeBindSource ce n'est pas bon (RecordCount=-1)
    et de toute façon je trouve ce test "limite"

    D'autres idées ?
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  2. #2
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 029
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 029
    Points : 40 928
    Points
    40 928
    Billets dans le blog
    62
    Par défaut
    Eurêka, une première solution simple en testant simplement s'il y a du texte dans la boite de recherche, fonctionnelle avec 10.4
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ListeFiltrée:= not SearchBox1.Text.IsEmpty;
    Moyennement satisfaisante et améliorable
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 14/10/2018, 13h18
  2. savoir si une liste est dans l'ordre alphabétique
    Par drylan73 dans le forum Général Python
    Réponses: 5
    Dernier message: 08/10/2018, 19h57
  3. comment savoir si une liste est evaluable?
    Par pepsister dans le forum Lisp
    Réponses: 15
    Dernier message: 15/03/2008, 14h40
  4. Comment savoir si une liste est vide?
    Par erfindel dans le forum Access
    Réponses: 2
    Dernier message: 14/02/2007, 15h20
  5. Savoir quand une variable ou un tableau est vide
    Par cryptorchild dans le forum Langage
    Réponses: 1
    Dernier message: 17/02/2006, 08h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo