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

Langage Delphi Discussion :

Sélection et TListView non active


Sujet :

Langage Delphi

  1. #1
    Nouveau membre du Club
    Inscrit en
    Juillet 2008
    Messages
    71
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Juillet 2008
    Messages : 71
    Points : 32
    Points
    32
    Par défaut Sélection et TListView non active
    Bonjour à tous,

    Voici une petite question dont je n'ai pu trouver réponse.

    J'ai un listview avec la propriété HIdeSelection à false. Quand je perd le focus sur le listview, les items sélectionnés apparaissent alors de couleur grisée. Est-il possible de garder la même couleur de selection que la listview soit active ou non?


    Merci d'avance.

  2. #2
    Membre habitué Avatar de phplive
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    179
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 179
    Points : 150
    Points
    150
    Par défaut
    Bjr

    Le listview n'est pas un modèle du genre dans l'art d'autoriser le développeur à le personnaliser. Sa façon de se redessiner est plutôt minable (à moins que ce ne soit l'implémentation dans la VCL) mais bref

    Tu peux essayer ceci



    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
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls, XPMan;
     
    type
      TListViewState = (lvsNormal, lvsFocused, lvsDisabled);
     
      TListItemState = (lisNormal, lisSelected);
     
      TListViewColorSet = record
        TextColor : TColor;
        BackgroundColor : TColor;
      end;
     
    const
       Orange =$000080FF;
       DefaultTextColor = clblack;
       DefaultBackgroundColor = clWhite;
       ListViewColors : array[TListViewState, TListItemState] of TListViewColorSet =
         (
           // lvsNormal
           (
             (TextColor : clBlack; BackgroundColor : clDefault),  // livNormal
             (TextColor : Orange; BackgroundColor : clBlack) // livSelected
            ),
     
           // lvsFocused
           (
             (TextColor : clBlack; BackgroundColor : clDefault),  // livNormal
             (TextColor : Orange; BackgroundColor : clBlack) // livSelected
            ),
     
           // lvsDisabled
           (
             (TextColor : clSilver; BackgroundColor : clDefault),  // livNormal
             (TextColor : clWhite; BackgroundColor : clBtnFace) // livSelected
            )
     
         );
     
    type
      TForm1 = class(TForm)
        ListView1: TListView;
        Edit1: TEdit;
        procedure ListView1CustomDrawItem(Sender: TCustomListView;
          Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
          Item: TListItem; SubItem: Integer; State: TCustomDrawState;
          var DefaultDraw: Boolean);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.dfm}
     
     
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      listView1.Enabled := not listView1.Enabled ;
    end;
     
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    listView1.DoubleBuffered := true;
    end;
     
     
     
    procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
    begin
      if not Sender.RowSelect then
      begin
        if Sender.Enabled then
        begin
          Sender.Canvas.Brush.Color := DefaultBackgroundColor;
          Sender.Canvas.Font.Color := DefaultTextColor;
        end
        else
        begin
          Sender.Canvas.Brush.Color := clWhite;
          Sender.Canvas.Font.Color := clSilver;
        end;
      end;
    end;
     
     
    procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
      Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
    var
      ListState : TListViewState;
      ItemState : TListItemState;
    begin
      // Force les couleurs par défaut
      Sender.Canvas.Brush.Color := DefaultBackgroundColor;
      Sender.Canvas.Font.Color := DefaultTextColor;
     
      if not Sender.Enabled then
      begin
        ListState := lvsDisabled;
      end
      else
      begin
        if Sender.Focused then
        begin
          ListState := lvsFocused;
        end
        else
        begin
          ListState := lvsNormal;
        end;
      end;
     
      if Item.Selected then
      begin
        ItemState := lisSelected;
      end
      else
      begin
        ItemState := lisNormal;
      end;
     
      if ListViewColors[ListState][ItemState].BackgroundColor <> clDefault then
        Sender.Canvas.Brush.Color := ListViewColors[ListState][ItemState].BackgroundColor;
     
      if ListViewColors[ListState][ItemState].TextColor  <> clDefault then
        Sender.Canvas.Font.Color := ListViewColors[ListState][ItemState].TextColor;
    end;
     
    end.
    Tu noteras le léger bug lorsque tu places un XPManifest et que tu désactives la liste ...

  3. #3
    Nouveau membre du Club
    Inscrit en
    Juillet 2008
    Messages
    71
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Juillet 2008
    Messages : 71
    Points : 32
    Points
    32
    Par défaut
    Merci phplive,

    je vais essayer ta méthode.

Discussions similaires

  1. Sélection plage feuille non active
    Par ccedos dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 31/05/2010, 17h00
  2. [Firefox] Flash non activé quand scroll firefox
    Par Tchinkatchuk dans le forum Flash
    Réponses: 4
    Dernier message: 18/08/2009, 23h27
  3. Réponses: 8
    Dernier message: 29/08/2006, 10h22
  4. [HTML/JS] désactivé et non activé
    Par nicoaix dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 08/06/2006, 21h05
  5. probleme lors d'une requete sql (controle non activé)
    Par junty dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 09/09/2005, 15h45

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