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 :

Problème avec Listview Insert


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 59
    Par défaut Problème avec Listview Insert
    Bonjour,

    Voilà j'utilise Chilkat comme DLL pour les FTP + XML et autres. Mais avec un Listview j'ai un problème d'index lorsque je veux insérer les contenus des dossiers dans mon listview par une boucle While.
    Si vous pouviez me dire où est mon erreur !? Car là je ne vois pas...

    Merci d'avance


    System.ArgumentOutOfRangeException: InvalidArgument=La valeur '3' n'est pas valide pour 'index'.
    Nom du paramètre : index

    En lisant mon code, vous comprendrez sans doute mieux :

    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
    Private Sub LancerDL()
            While ListView2.Items.Count > 0
                If OldPath <> "" Then FTP.GetCurrentRemoteDir()
                If Button1.Text = "Lancer !" Then
                    Abort = False
                    Button1.Text = "Annuler !"
                    ListView2.Enabled = False
                    For Each item As ListViewItem In ListView2.Items
                        If item.StateImageIndex = 3 Then
                            If Microsoft.VisualBasic.Right(item.Text, 4) = ".flv" Then
                                Dim fichier() = Split(item.SubItems(1).Text, "\")
                                If Not Directory.Exists(Replace(item.SubItems(1).Text, fichier(fichier.Length - 1), "")) Then
                                    Directory.CreateDirectory(Replace(item.SubItems(1).Text, fichier(fichier.Length - 1), ""))
                                End If
                                Success = FTP.AsyncGetFileStart(item.SubItems(0).Text, item.SubItems(1).Text)
                                If (Not Success) Then
                                    MessageBox.Show(FTP.LastErrorText)
                                    Exit Sub
                                End If
                                ProgressBar1.Maximum = Replace(item.SubItems(2).Text, " Mo", "") * 1048576
                                While Not FTP.AsyncFinished
                                    System.Threading.Thread.Sleep(100)
                                    Application.DoEvents()
                                    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                                    ' /!\ ERREUR ICI /!\ Index 3 Invalide Si précédemment c'est une boucle While''''''
                                    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                                    item.SubItems(3).Text = FormatNumber(FTP.DownloadRate / 1024, 2) & " Kb/s"       '
                                    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                                    ProgressBar1.Value = FormatNumber(FTP.AsyncBytesReceived / 1048576, 2) * 1048576
                                    If Abort Then
                                        FTP.AsyncAbort()
                                        ListView2.Enabled = True
                                        FTP.ChangeRemoteDir(OldPath)
                                        OldPath = ""
                                        Exit Sub
                                    End If
                                End While
                                If Not FTP.AsyncSuccess Then
                                    MessageBox.Show(FTP.AsyncLog)
                                End If
                                item.Remove()
                                ProgressBar1.Value = 0
                            Else
                                Dim n As Long
                                If Not Directory.Exists(item.SubItems(1).Text) Then
                                    Directory.CreateDirectory(item.SubItems(1).Text)
                                End If
                                FTP.ChangeRemoteDir(item.SubItems(0).Text)
                                n = FTP.NumFilesAndDirs
                                If (n < 0) Then
                                    EcrireLog(RichTextBox1, FTP.LastErrorText, Color.Red)
                                    Exit Sub
                                End If
                                EcrireLog(RichTextBox1, "Chargement de la liste des dossiers...", Color.Green)
                                If (n > 0) Then
                                    For i = 0 To n - 1
                                        If (FTP.GetIsDirectory(i) = True) Then
                                            Dim items As String() = New String(2) {}
                                            items(0) = "D:\tmp" & Replace(FTP.GetCurrentRemoteDir(), "/", "\") & "\" & FTP.GetFilename(i)
                                            items(1) = ""
                                            ListView2.Items.Insert(0, FTP.GetCurrentRemoteDir() & "/" & FTP.GetFilename(i), 1).SubItems.AddRange(items)
                                            ListView2.Items(0).StateImageIndex = 3
                                        Else
                                            Dim items As String() = New String(2) {}
                                            items(0) = "D:\tmp" & Replace(FTP.GetCurrentRemoteDir(), "/", "\") & "\" & FTP.GetFilename(i)
                                            items(1) = ConvertFileSize(FTP.GetSize(i))
                                            ListView2.Items.Insert(0, FTP.GetCurrentRemoteDir() & "/" & FTP.GetFilename(i), 2).SubItems.AddRange(items)
                                            ListView2.Items(0).StateImageIndex = 3
                                        End If
                                    Next
                                    item.Remove()
                                End If
                            End If
                        End If
                    Next
                    FTP.ChangeRemoteDir(OldPath)
                    OldPath = ""
                    ListView2.Enabled = True
                    Button1.Text = "Lancer !"
                Else
                    Dim reponse = MessageBox.Show("Etes-vous sûr de vouloir annuler les téléchargements et uploads en cours ?", "Annuler", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
                    Select Case reponse
                        Case Windows.Forms.DialogResult.Yes
                            Abort = True
                    End Select
                End If
            End While
            Button1.Text = "Lancer !"
        End Sub

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 59
    Par défaut
    J'ai trouvé la solution !
    Je la mets au cas où quelqu'un aurait le même problème

    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
                                        If (FTP.GetIsDirectory(i) = True) Then
                                            Dim items As String() = New String(2) {}
                                            items(0) = "D:\tmp" & Replace(FTP.GetCurrentRemoteDir(), "/", "\") & "\" & FTP.GetFilename(i)
                                            items(1) = ""
                                            items(2) = ""
                                            ListView2.Items.Insert(0, FTP.GetCurrentRemoteDir() & "/" & FTP.GetFilename(i), 1).SubItems.AddRange(items)
                                            ListView2.Items(0).StateImageIndex = 3
                                        Else
                                            Dim items As String() = New String(2) {}
                                            items(0) = "D:\tmp" & Replace(FTP.GetCurrentRemoteDir(), "/", "\") & "\" & FTP.GetFilename(i)
                                            items(1) = ConvertFileSize(FTP.GetSizeByName(FTP.GetFilename(i)))
                                            items(2) = ""
                                            ListView2.Items.Insert(0, FTP.GetCurrentRemoteDir() & "/" & FTP.GetFilename(i), 2).SubItems.AddRange(items)
                                            ListView2.Items(0).StateImageIndex = 3
                                        End If

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

Discussions similaires

  1. Problème avec un INSERT
    Par nnj dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 01/08/2006, 15h51
  2. [C#] problème avec l'insertion des données dans MySQL
    Par madica dans le forum Accès aux données
    Réponses: 7
    Dernier message: 08/11/2005, 13h27
  3. [DREAM MX] Problème avec une insertion d'une anim' flash
    Par Mout85 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 16/09/2005, 12h47
  4. [MFC] problème avec les insertions dans CComboBox
    Par Joeleclems dans le forum MFC
    Réponses: 12
    Dernier message: 11/06/2004, 15h31
  5. [C#] Problème avec ListView
    Par yannick dans le forum Windows Forms
    Réponses: 4
    Dernier message: 03/06/2004, 17h29

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