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

C# Discussion :

Synchronized ListBox objects [Débutant]


Sujet :

C#

  1. #1
    Membre régulier
    Inscrit en
    Juin 2009
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 114
    Points : 94
    Points
    94
    Par défaut Synchronized ListBox objects
    Bonjour bonjour,

    je soumet un petit probléme que je peux contourner ... mais comme definitivement il y'a quelque chose qui m'echape ...

    je veux synchronisé deux listbox qui non pas les même éléments mais qui ont la même taille avec l'event selectedindexchanged je peux deplacer les deux listbox ... sur code project je suis tomber la dessus
    -----------------------------------------------------------------
    Before couple of days I had a task where I must synchronize two ListBox objects. I have fount out, that ListBox object doesn't have any property which allow to accomplish this. After a few hours of googling I found code of class that inherited from ListBox class. Here is the code of that class:
    ---------------------------------------------------------------------
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.ComponentModel;
    using System.Runtime.InteropServices;
    namespace SyncLists
    {
        class SyncListBox : System.Windows.Forms.ListBox
        {
            [Category("Action")]
            private const int WM_HSCROLL = 0x114;
            private const int WM_VSCROLL = 0x115;
            public event ScrollEventHandler OnHorizontalScroll;
            public event ScrollEventHandler OnVerticalScroll;
     
            private const int SB_LINEUP = 0;
            private const int SB_LINELEFT = 0;
            private const int SB_LINEDOWN = 1;
            private const int SB_LINERIGHT = 1;
            private const int SB_PAGEUP = 2;
            private const int SB_PAGELEFT = 2;
            private const int SB_PAGEDOWN = 3;
            private const int SB_PAGERIGHT = 3;
            private const int SB_THUMBPOSITION = 4;
            private const int SB_THUMBTRACK = 5;
            private const int SB_PAGETOP = 6;
            private const int SB_LEFT = 6;
            private const int SB_PAGEBOTTOM = 7;
            private const int SB_RIGHT = 7;
            private const int SB_ENDSCROLL = 8;
            private const int SIF_TRACKPOS = 0x10;
            private const int SIF_RANGE = 0x1;
            private const int SIF_POS = 0x4;
            private const int SIF_PAGE = 0x2;
            private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
            [DllImport("user32.dll", SetLastError = true)]
            private static extern int GetScrollInfo(
            IntPtr hWnd, int n, ref ScrollInfoStruct lpScrollInfo);
     
            private struct ScrollInfoStruct
            {
                public int cbSize;
                public int fMask;
                public int nMin;
                public int nMax;
                public int nPage;
                public int nPos;
                public int nTrackPos;
            }
            protected override void WndProc(ref System.Windows.Forms.Message msg)
            {
                if (msg.Msg == WM_HSCROLL)
                {
                    if (OnHorizontalScroll != null)
                    {
                        ScrollInfoStruct si = new ScrollInfoStruct();
                        si.fMask = SIF_ALL;
                        si.cbSize = Marshal.SizeOf(si);
                        GetScrollInfo(msg.HWnd, 0, ref si);
                        if (msg.WParam.ToInt32() == SB_ENDSCROLL)
                        {
                            ScrollEventArgs sargs = new ScrollEventArgs(
                            ScrollEventType.EndScroll,
                            si.nPos);
                            OnHorizontalScroll(this, sargs);
                        }
                    }
                }
                if (msg.Msg == WM_VSCROLL)
                {
                    if (OnVerticalScroll != null)
                    {
                        ScrollInfoStruct si = new ScrollInfoStruct();
                        si.fMask = SIF_ALL;
                        si.cbSize = Marshal.SizeOf(si);
                        GetScrollInfo(msg.HWnd, 0, ref si);
                        if (msg.WParam.ToInt32() == SB_ENDSCROLL)
                        {
                            ScrollEventArgs sargs = new ScrollEventArgs(
                            ScrollEventType.EndScroll,
                            si.nPos);
                            OnVerticalScroll(this, sargs);
                        }
                    }
                }
                base.WndProc(ref msg);
            }
     
            private void InitializeComponent()
            {
                this.SuspendLayout();
                // 
                // scrolled
                // 
                this.Size = new System.Drawing.Size(120, 95);
                this.ResumeLayout(false);
            }
        }
    }
    ------------------------------------------------------------------------
    add two SyncListBox objects (syncListView1 and syncListView2) on the form and add following code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    private void syncListView2_OnVerticalScroll(object sender, ScrollEventArgs e)
    {
        syncListView1.TopIndex = syncListView2.TopIndex;
    }
     
    private void syncListView1_OnVerticalScroll(object sender, ScrollEventArgs e)
    {
        syncListView2.TopIndex = syncListView1.TopIndex;
    }
    -------------------------------------------------------------------------
    et la c'est le drame je vois bien qu'il a crée une classe dérivé de listbox avec les deux scroll ..

    alors je tourne sa dans tout les sens mais en recompilant la solution toujours pas d'objet syncListBox qui apparais ...

    j'ai bien recopié la classe ... je la remet dans le winform mais impossible d'utilisé un synclistBox

    enfer et damnation .. quelqu'un pourrais t'il m'aiguiller ???

  2. #2
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 749
    Points
    39 749
    Par défaut
    Mets la classe dans ton projet, recompile, et le nouveau contrôle devrait apparaitre dans ta boite à outils (dans une catégorie séparée du reste qui correspond à ton projet)

  3. #3
    Membre régulier
    Inscrit en
    Juin 2009
    Messages
    114
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 114
    Points : 94
    Points
    94
    Par défaut
    merci beaucoup ...

    j'ai mis 2 heures de plus, j'avais pas compris qu'il fallais réactualiser la boite à outils ....

    voila voila allez j'attaque la partie xml de l'appli ....

    sa devrais être plus simple

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

Discussions similaires

  1. [PowerShell] compare-object et listbox
    Par Baka59 dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 22/10/2013, 00h17
  2. Réponses: 3
    Dernier message: 08/04/2013, 08h26
  3. Mettre un object dans ListBox
    Par Ardely dans le forum Delphi
    Réponses: 10
    Dernier message: 03/01/2007, 22h49
  4. [VisualC++6.0]Object Array dans un ListBox
    Par thomfort dans le forum MFC
    Réponses: 16
    Dernier message: 16/05/2006, 18h37
  5. Réponses: 6
    Dernier message: 25/03/2002, 21h11

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