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

Windows Forms Discussion :

[VB.NET] Mise en place d'une progress bar


Sujet :

Windows Forms

  1. #1
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut [VB.NET] Mise en place d'une progress bar
    Salut j'ai un probleme pour inserer une progress bar dans un programme.
    En fait lorsque j insere une progress bar et que le traitement qui est lié a cette progress bar est dans le code la form y a pas de pb car marche, mais lorsque le traitement est situé dans un module (qui ne peut pas agir sur les controles de la form), je ne vois pas du tout comment faire
    Quelqu un pourrait m aider SVP
    ++

  2. #2
    Membre du Club
    Inscrit en
    Décembre 2003
    Messages
    56
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 56
    Points : 64
    Points
    64
    Par défaut
    Salut,
    une solution consiste à déclencher des événements à partir de ton module, que tu récupères dans ton form...

    1) Définit une classe publique dérivant de EventArgs. Exemple (en C# ) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public class ProgressionEventArgs : EventArgs
    {
      private int m_Progression;
     
       public ProgressionEventArgs(int progression)
      {
         m_Progression = progression;
      }
     
      public int Progression
      {
         get { return this.m_Progression; }
      }
    }
    2) Déclare dans ton module un événement de type ProgressionEventArgs, et déclenche le à chaque fois que ton traitement avance

    3) Dans ton form tu n'a plus qu'à écouter les events...

  3. #3
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    ok je vais essayer merci

  4. #4
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    bon en fait je vais plutot m'orienter vers une listview qui calculera le pourcentage d'avancement de mon traitement donc j aimerai que le pourcentage augmente au fur et a musure et que il soit écrit sur la meme ligne.

    Bon comme j'ai pas compris ta solution précedente, est ce que tu pourrais me donner plus de détail pour le réaliser avec une listview ?
    Merci


    En fait pour l instant j'ai fait un truc comme ca tupourrais me dire si je suis dans la bonne voie
    voila mon traitement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    For i = 0 to n 
    Compteur(i,n)
    'traitement 
    Next
    Fonction qui me calcule le pourcentage d'avacement du projet

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     Function Compteur(ByVal i As Integer, ByVal n As Integer) As Double
            Math.Round(100 * i / n)
        End Function
    etr en fait il faudrai que cette fonction affiche le resultat dans la list view a chaque fois que le pourcentage augmente

  5. #5
    Membre du Club
    Inscrit en
    Décembre 2003
    Messages
    56
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 56
    Points : 64
    Points
    64
    Par défaut
    OK je vais essayer de détailler un petit peu plus
    En C#

    Le principe est exactement le même que pour l'interception du clic sur un bouton par exemple.

    Déjà place la classe ProgressionEventArgs dans ton module, où au moins dans un emplacement accessible par ton module.
    Ceci étant fait il faut écrire un délégué qui permettra l'interception de l'événement. Je te conseille de la faire dans un fichier à part.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public delegate void ProgressionHandler(object sender, ProgressionEventArgs e);
    Maintenant, dans la classe effectuant ton traitement, tu dois déclarer en public un event de type ProgressionEventArgs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public event ProgressionHandler ProgressionTraitement;
    Cette ligne de code indique que ta classe est susceptible de lever des événements ProgressionTraitement, de la même manière que la classe Button peut générer des event Click.
    Du coup tu peux modifier ton traitement de la manière suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    For i = 0 to n
      if(null != ProgressionTraitement)
        ProgressionTraitement(this, new ProgressionEventArgs(Compteur(i,n));
      'traitement
    Next
    ProgressionTraitement(...) déclenche un événement avec le % d'avancement de ton traitement.

    Dernière étape : dans ton form, juste avant de lancer le traitement tu dois écouter les événements ProgressionTraitement :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    objTraitement.ProgressionTraitement += new ProgressionHandler(Fct_Traitement);
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    private void ProgressionTraitement(object sender, ProgressionEventArgs e)
    {
      int Pourcentage = e.Progression;
      // ici mise à jour de ta progressbar ou de ta listview
    }
    J'espère que j'ai été assez clair

  6. #6
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    merci de ta réponse mais visiblement je dois avoir du mal car j y arrive pas je te met ce que j'ai fait

    dans mon module :
    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
     
      Public Class ProgressionEventArgs
            Inherits EventArgs
            Dim m_Progression As Integer
            Public Sub ProgressionEventArgs(ByVal progression As Integer)
                m_Progression = progression
            End Sub
            Public Function Progression() As Integer
                Progression = m_Progression
            End Function
            Public ProgressionTraitement As ProgressionHandler
        End Class
     
     
     
        Delegate Sub ProgressionHandler(ByVal sender As Object, ByVal e As ProgressionEventArgs)
    et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    For i = 2 To n
                If ProgressionTraitement <> System.DBNull Then
                    ProgressionEventArgs.ProgressionTraitement(sender, New ProgressionEventArgs(Compteur(i, n)))
                End If
    next
    et dans le code de la form

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     
        Private Sub ProgressionTraitement(ByVal sender As Object, ByVal e As ProgressionEventArgs)
            Dim Pourcentage As Integer = e.Progression
            LstView_Resultat.Items.Add("Traitement en cours..." & Pourcentage & "%")
        End Sub
    je dois sans doute manquer une étape

  7. #7
    Membre du Club
    Inscrit en
    Décembre 2003
    Messages
    56
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 56
    Points : 64
    Points
    64
    Par défaut
    je dois sans doute manquer une étape
    En fait tu as fais quelques petites erreurs

    1) Ce n'est pas dans la classe ProgressionEventArgs que tu dois déclarer ProgressionTraitement, mais plutôt dans la classe qui implémente ton traitement, car c'est bien elle qui va déclencher des events.

    2)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Public ProgressionTraitement As ProgressionHandler
    A mon avis cette déclaration est incomplète... En C# il faut utiliser le mot-clé event. Il doit y avoir une syntaxe similaire dans VB.NET... peut-être with events comme dans VB6 ? A vérifier.

    3)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If ProgressionTraitement <> System.DBNull
    Il ne faut pas comparer à System.DBNull.Value, mais tester si l'objet existe...
    En syntaxe VB6, il faudrait mettre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If Not ProgressionTraitement Is Nothing
    Ce code permet de tester si l'événement va être intercepté quelque part, sinon c'est pas la peine de le déclencher...

    4) Est ce que dans ton form tu as écrit une ligne de code du genre (C#, désolé) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    objTraitement.ProgressionTraitement += new ProgressionHandler(ProgressionTraitement);
    Si ce n'est pas le cas tu ne recevras aucun event...

    Bon courage !

    PS : Essaie de trouver un tutorial sur les events...

  8. #8
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    58
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 58
    Points : 70
    Points
    70
    Par défaut
    Salut,

    Peut être pour commencer vaut-il mieux faire encore plus simple en se passant de classe progressionEventArgs et de delégué:

    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
    Public Class Calcul    'La Classe implémentant la routine de calcul
     
    Public NbrEssais as integer 'Champ public qui contient le nombre d'essais
                            'Normalement il faut mettre le champ private et une property readonly publique
     
    Public Event NewEssaiEvent() 'Simple Evenement sans parametre
     
    Public sub Calculer 'Procedeure de calcul
      me.nbrEssais = 0 'Compteur à 0
      Dim i as integer
      for i = 0 to FinCalcul
        'Traitement 
         Me.nbrEssais += 1 'on augmente le compteur
         RaiseEvent NewEssaiEvent() 'on déclenche l'évènement
      next i
     End Sub
    End Class
    dans le form:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
      Public WithEvents Calcul as new CalculClass 'Classe de calcul qui va générer les evenements
     
      Private Sub Calcul_NewEssaiEvent() Handles Calcul.NewEssaiEvent 'Ecoute de l'event NewEssaiEvent déclenché par l'objet Calcul
        Me.ProgressBar.Value = Calcul.NbrEssais 'ou n'importe quelle routine d'affichage de listview ou de ce qu'on veut
      End Sub
    Il suffit de lancer Calcul.Calculer pour voir la progressBar avancer.

  9. #9
    Membre du Club
    Inscrit en
    Décembre 2003
    Messages
    56
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 56
    Points : 64
    Points
    64
    Par défaut
    Effectivement c une bonne idée... Ca va un peu simplifier le problème.

  10. #10
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    Pffffffff comme je galère
    En tout cas merci a tous les deux de m avoir aidé je sens que je vais y passer la journée

    ++

  11. #11
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    je n en pui plus

    bon voila le code de ma form :
    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
     
     Private Sub Btn_App_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn_App.Click
            Dim Fich_Xml_Rub_Temp As String
            Dim i As Integer = 0
            For i = 0 To LstView_Rub.Items.Count - 1
                If LstView_Rub.Items(i).Checked Then
                    Nom = LstView_Rub.Items(i).SubItems(1).Text
                    RD1 = LstView_Rub.Items(i).SubItems(2).Text
                    Op1 = LstView_Rub.Items(i).SubItems(3).Text
                    Val1 = LstView_Rub.Items(i).SubItems(4).Text
                    Coor = LstView_Rub.Items(i).SubItems(5).Text
                    RD2 = LstView_Rub.Items(i).SubItems(6).Text
                    Op2 = LstView_Rub.Items(i).SubItems(7).Text
                    Val2 = LstView_Rub.Items(i).SubItems(8).Text
                    RubCalcul1 = LstView_Rub.Items(i).SubItems(9).Text
                    RubCalcul2 = LstView_Rub.Items(i).SubItems(10).Text
                    OpCalcul = LstView_Rub.Items(i).SubItems(11).Text
                    RubCalcul3 = LstView_Rub.Items(i).SubItems(12).Text
                End If
            Next
            ReDim Preserve T_Nom(TestRubrique)
            T_Nom(TestRubrique) = Nom
            TestRubrique += 1
            Cursor.Current = Cursors.WaitCursor
            Modif_Xml(NbChamps, Nom, Fich_Xml_Rub, Chemin_Xml, RD1, Op1, Val1, Coor, RD2, Op2, Val2, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul)
        End Sub

    Voila ma procédure dans le mon module :
    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
     
    Sub Modif_Xml(ByRef NbChamp As Integer, ByVal Nom As String, ByVal Fich_Xml_Rub As String, ByVal Chemin_Xml As String, ByVal RD1 As String, ByVal Op1 As String, ByVal Val1 As String, ByVal Coor As String, ByVal RD2 As String, ByVal Op2 As String, ByVal Val2 As String, ByVal RubCalcul1 As String, ByVal RubCalcul2 As String, ByVal RubCalcul3 As String, ByVal OpCalcul As String)
                Dim d As New XmlDocument()
                Dim ProgressionEventArgs As System.EventArgs
                Dim RDAtt1 As String
                Dim ValAtt1 As String
                Dim RubCalculAtt1 As String
                Dim RubCalculAtt2 As String
                Dim RubCalculAtt3 As String
                Dim RDAtt2 As String
                Dim ValAtt2 As String
                Dim Xml_Read As New XmlTextReader(Fich_Xml_Rub)
                d.Load(Chemin_Xml)
                Do While Xml_Read.Value <> Nom
                    Xml_Read.Read()
                Loop
                Do While Xml_Read.Name <> "Rubrique"
                    If Xml_Read.Name = "RubriqueDeclencheuse" Then
                        Xml_Read.MoveToAttribute("Champ")
                        RD1 = Xml_Read.GetAttribute(0)
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "Valeur" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            Val1 = Xml_Read.GetAttribute(0)
                            ValAtt1 = Val1
                        Else
                            ValAtt1 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueCalcul1" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RubCalcul1 = Xml_Read.GetAttribute(0)
                            RubCalculAtt1 = RubCalcul1
                        Else
                            RubCalculAtt1 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueCalcul2" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RubCalcul2 = Xml_Read.GetAttribute(0)
                            RubCalculAtt2 = RubCalcul2
                        Else
                            RubCalculAtt2 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueCalcul3" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RubCalcul3 = Xml_Read.GetAttribute(0)
                            RubCalculAtt3 = RubCalcul3
                        Else
                            RubCalculAtt3 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueDeclencheuseRestriction" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RD2 = Xml_Read.GetAttribute(0)
                            RDAtt2 = RD2
                        Else
                            RDAtt2 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "ValeurRestriction" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            Val2 = Xml_Read.GetAttribute(0)
                            ValAtt2 = Val2
                        Else
                            ValAtt2 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    Xml_Read.Read()
                Loop
                Xml_Read.Close()
                Dim root As XmlNode = d.DocumentElement
                Dim i As Integer = 2
                Dim n As Integer
                Dim format As String
                Dim NodeCount As XmlNode = root.SelectSingleNode("//ligne[position () = last()]")
                n = NodeCount.Attributes("id").Value
                If RubCalcul1.StartsWith("Champ") = False Then
                    Ajoutchamp(n, Chemin_Xml, d, NbChamp, RubCalcul1, root)
                End If
                For i = 2 To n
                    RaiseEvent ProgressionTraitement(Me, New ProgressionEventArgs())
                    'traitement Compteur(i, n)
                    Dim NodeRD1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & RD1)
                    If RD2 = "Vide" Then
                        If ValAtt1 = "" Then
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(Verif_Format(Val1), Val1), Op1)
                            If FirstTest = True Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        Else
                            Dim NodeVal1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val1)
     
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(GetFormatNode(NodeVal1), NodeVal1.InnerText), Op1)
                            If FirstTest = True Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        End If
                    Else
                        Dim NodeRD2 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & RD2)
                        If ValAtt1 = "" And ValAtt2 <> "" Then
                            Dim NodeVal2 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val2)
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(Verif_Format(Val1), Val1), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD2), NodeRD2.InnerText), CheckFormat(GetFormatNode(NodeVal2), NodeVal2.InnerText), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        ElseIf ValAtt1 <> "" And ValAtt2 = "" Then
                            Dim NodeVal1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val1)
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(GetFormatNode(NodeVal1), NodeVal1.InnerText), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD2), NodeRD2.InnerText), CheckFormat(Verif_Format(Val2), Val2), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        ElseIf ValAtt1 = "" And ValAtt2 = "" Then
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(Verif_Format(Val1), Val1), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD2), NodeRD2.InnerText), CheckFormat(Verif_Format(Val2), Val2), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        Else
                            Dim NodeVal1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val1)
                            Dim NodeVal2 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val2)
                            format = GetFormatNode(NodeVal1)
                            format = GetFormatNode(NodeVal2)
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(format, NodeRD1.InnerText), CheckFormat(format, NodeVal1.InnerText), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(format, NodeRD2.InnerText), CheckFormat(format, NodeVal2.InnerText), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        End If
                    End If
                Next
                d.Save(Chemin_Xml)
            End Sub

    Comment faire ?

    je crakkkkkkkkkkkkkkkkkkkkkkk

  12. #12
    Membre du Club
    Inscrit en
    Décembre 2003
    Messages
    56
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 56
    Points : 64
    Points
    64
    Par défaut
    je crakkkkkkkkkkkkkkkkkkkkkkk
    Tu y est presque

    Il faut que tu transformes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub Fct_Traitement(ByVal sender As Object, ByVal e As ProgressionEventArgs)
            LstView_Resultat.Items.Add("Traitement en cours...")
    End Sub
    en

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub Fct_Traitement(ByVal sender As Object, ByVal e As ProgressionEventArgs) Handles TonObjet.ProgressionTraitement
            LstView_Resultat.Items.Add("Traitement en cours...")
    End Sub
    Si j'ai bien compris la MSDN, Handles TonObjet.ProgressionTraitement signifie qu'à chaque fois quel l'event ProgressionTraitement sera déclenché, la fonction Fct_Traitement sera appelée. C'est l'équivalent C# de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    objTraitement.ProgressionTraitement += new ProgressionHandler(Fct_Traitement);
    Evidemment, pour que ça marche, la variable TonObjet doit être donnée membre de ton form.

    En espérant que ça puisse t'aider

  13. #13
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    Bon j'avance
    J'ai réussi a faire un truc avec la méthode de Bifidus

    Dans mon module :
    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
     
    Public Class Calcul    'La Classe implémentant la routine de calcul 
     
            Public Pourcentage As Integer 'Champ public qui contient le nombre d'essais 
            'Normalement il faut mettre le champ private et une property readonly publique 
     
            Public Event NewEssaiEvent() 'Simple Evenement sans parametre 
     
            Public Sub Modif_Xml(ByRef NbChamp As Integer, ByVal Nom As String, ByVal Fich_Xml_Rub As String, ByVal Chemin_Xml As String, ByVal RD1 As String, ByVal Op1 As String, ByVal Val1 As String, ByVal Coor As String, ByVal RD2 As String, ByVal Op2 As String, ByVal Val2 As String, ByVal RubCalcul1 As String, ByVal RubCalcul2 As String, ByVal RubCalcul3 As String, ByVal OpCalcul As String)
                Me.Pourcentage = 0 'Compteur à 0 
                Dim d As New XmlDocument()
                Dim ProgressionEventArgs As System.EventArgs
                Dim RDAtt1 As String
                Dim ValAtt1 As String
                Dim RubCalculAtt1 As String
                Dim RubCalculAtt2 As String
                Dim RubCalculAtt3 As String
                Dim RDAtt2 As String
                Dim ValAtt2 As String
                Dim Xml_Read As New XmlTextReader(Fich_Xml_Rub)
                d.Load(Chemin_Xml)
                Do While Xml_Read.Value <> Nom
                    Xml_Read.Read()
                Loop
                Do While Xml_Read.Name <> "Rubrique"
                    If Xml_Read.Name = "RubriqueDeclencheuse" Then
                        Xml_Read.MoveToAttribute("Champ")
                        RD1 = Xml_Read.GetAttribute(0)
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "Valeur" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            Val1 = Xml_Read.GetAttribute(0)
                            ValAtt1 = Val1
                        Else
                            ValAtt1 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueCalcul1" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RubCalcul1 = Xml_Read.GetAttribute(0)
                            RubCalculAtt1 = RubCalcul1
                        Else
                            RubCalculAtt1 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueCalcul2" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RubCalcul2 = Xml_Read.GetAttribute(0)
                            RubCalculAtt2 = RubCalcul2
                        Else
                            RubCalculAtt2 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueCalcul3" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RubCalcul3 = Xml_Read.GetAttribute(0)
                            RubCalculAtt3 = RubCalcul3
                        Else
                            RubCalculAtt3 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "RubriqueDeclencheuseRestriction" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            RD2 = Xml_Read.GetAttribute(0)
                            RDAtt2 = RD2
                        Else
                            RDAtt2 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    If Xml_Read.Name = "ValeurRestriction" Then
                        Xml_Read.MoveToAttribute("Champ")
                        If Xml_Read.GetAttribute(0) <> "" Then
                            Val2 = Xml_Read.GetAttribute(0)
                            ValAtt2 = Val2
                        Else
                            ValAtt2 = ""
                        End If
                        Xml_Read.Read()
                        Xml_Read.Read()
                    End If
                    Xml_Read.Read()
                Loop
                Xml_Read.Close()
                Dim root As XmlNode = d.DocumentElement
                Dim i As Integer = 2
                Dim n As Integer
                Dim format As String
                Dim NodeCount As XmlNode = root.SelectSingleNode("//ligne[position () = last()]")
                n = NodeCount.Attributes("id").Value
                If RubCalcul1.StartsWith("Champ") = False Then
                    Ajoutchamp(n, Chemin_Xml, d, NbChamp, RubCalcul1, root)
                End If
                For i = 2 To n
                    Me.Pourcentage = Math.Round((100 * i) / n) 'on augmente le compteur 
                                        RaiseEvent NewEssaiEvent() 'on déclenche l'évènement 
     
                    Dim NodeRD1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & RD1)
                    If RD2 = "Vide" Then
                        If ValAtt1 = "" Then
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(Verif_Format(Val1), Val1), Op1)
                            If FirstTest = True Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        Else
                            Dim NodeVal1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val1)
     
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(GetFormatNode(NodeVal1), NodeVal1.InnerText), Op1)
                            If FirstTest = True Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        End If
                    Else
                        Dim NodeRD2 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & RD2)
                        If ValAtt1 = "" And ValAtt2 <> "" Then
                            Dim NodeVal2 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val2)
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(Verif_Format(Val1), Val1), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD2), NodeRD2.InnerText), CheckFormat(GetFormatNode(NodeVal2), NodeVal2.InnerText), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        ElseIf ValAtt1 <> "" And ValAtt2 = "" Then
                            Dim NodeVal1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val1)
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(GetFormatNode(NodeVal1), NodeVal1.InnerText), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD2), NodeRD2.InnerText), CheckFormat(Verif_Format(Val2), Val2), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        ElseIf ValAtt1 = "" And ValAtt2 = "" Then
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD1), NodeRD1.InnerText), CheckFormat(Verif_Format(Val1), Val1), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(GetFormatNode(NodeRD2), NodeRD2.InnerText), CheckFormat(Verif_Format(Val2), Val2), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        Else
                            Dim NodeVal1 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val1)
                            Dim NodeVal2 As XmlNode = root.SelectSingleNode("//ligne[@id='" & i & "']//" & Val2)
                            format = GetFormatNode(NodeVal1)
                            format = GetFormatNode(NodeVal2)
                            Dim firstTest As Boolean = CheckRelational(CheckFormat(format, NodeRD1.InnerText), CheckFormat(format, NodeVal1.InnerText), Op1)
                            Dim secondTest As Boolean = CheckRelational(CheckFormat(format, NodeRD2.InnerText), CheckFormat(format, NodeVal2.InnerText), Op2)
                            If CheckLogical(firstTest, secondTest, Coor) Then
                                Traitement_Xml(NbChamp, i, root, d, RubCalcul1, RubCalcul2, RubCalcul3, OpCalcul, RDAtt1, RDAtt2, RubCalculAtt1, RubCalculAtt2, RubCalculAtt3, ValAtt1, ValAtt2)
                            End If
                        End If
                    End If
                Next
                d.Save(Chemin_Xml)
            End Sub
        End Class
    et dons le code de la form :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    Friend WithEvents Calcul As New Calcul() 'Classe de calcul qui va générer les evenements 
        Private Sub Calcul_NewEssaiEvent() Handles Calcul.NewEssaiEvent 'Ecoute de l'event NewEssaiEvent déclenché par l'objet Calcul 
            Me.LstView_Resultat.Items.Add(Calcul.Pourcentage).EnsureVisible() 'ou n'importe quelle routine d'affichage de listview ou de ce qu'on veut 
        End Sub
    Le pb c'est que je voudrais que m a list view se rafraichissent lorsque le pourcentage change.

    En tout cas merci a tous pour m 'avoir aiser jusqu ici :=)

  14. #14
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    58
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 58
    Points : 70
    Points
    70
    Par défaut
    Honnetement j'ai eu la flemme de lire tout ton code...
    Mais des trucs comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Public Sub Modif_Xml(ByRef NbChamp As Integer, ByVal Nom As String, ByVal Fich_Xml_Rub As String, ByVal Chemin_Xml As String, ByVal RD1 As String, ByVal Op1 As String, ByVal Val1 As String, ByVal Coor As String, ByVal RD2 As String, ByVal Op2 As String, ByVal Val2 As String, ByVal RubCalcul1 As String, ByVal RubCalcul2 As String, ByVal RubCalcul3 As String, ByVal OpCalcul As String)
    Ca fait plutot VB6 que .NET..
    En POO on fait plutot un objet qui a pour propriétés tes parametres auquel on applique une méthode Modif_Xml.
    Sinon tu veux rafraichir l'affichage d'un ListView a chaque fois qu'il y a un traitement trés léger (y'a beaucoup de lignes mais c'est trés leger en temps proc) sur un fichier XML !?
    Il y a un autre problème que le simple déclenchement de l'event c'est les temps de traitement.
    La modif du fichier XML une fois qu'il est chargé en mémoire doit etre 100 fois plus rapide que le refresh du ListView qui est une opération trés lourde.
    D'habitude on fait plutot le contraire: on désactive les rafraichissements (BeginUpdate) des controles tant qu'on touche à leur sources et on rafraichit l'affichage lorsque l'on a fini (EndUpdate).
    EnsureVisible se contente de faire un scrolling du ListView afin que l'élément ajouté soit dans la zone visible, mais il ne force pas un repeint du ListView pour qu'il affiche le nouvel element.

  15. #15
    Membre habitué Avatar de Hoegaarden
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Avril 2004
    Messages : 362
    Points : 175
    Points
    175
    Par défaut
    En fait j ai trouvé une solution alternative je vais mettre le pourcentage d'avancement de mon traitement dans une statut bar
    Merci a tous pour votre aide a bientot

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

Discussions similaires

  1. [vba] mise en place d'une barre de progression
    Par ancel17 dans le forum Excel
    Réponses: 7
    Dernier message: 11/12/2013, 11h28
  2. Réponses: 4
    Dernier message: 17/04/2009, 11h41
  3. Réponses: 3
    Dernier message: 31/10/2007, 11h38
  4. [.NET C# VS05] Evolution d'une progress bar
    Par NeraOne dans le forum Windows Forms
    Réponses: 2
    Dernier message: 25/06/2007, 17h23
  5. Mise en place d'une solution Data Guard 9i R2
    Par user_oracle dans le forum Oracle
    Réponses: 4
    Dernier message: 16/02/2005, 10h12

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