Défilement scrollbar

Résolu
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013 - 1 juin 2009 à 08:31
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 - 1 juin 2009 à 15:34
Bonjour à tous,

Petits soucis, j'ai un listbox contenant une liste de nom, j'ai lié ce listebox avec un scrollbar. Le problème c'est que le défilement se fait uniquement que dans un sens. Besoin donc d'un coup de pouce.
Voici mon code :

Private
Sub VScrollBar1_ValueChanged(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles VScrollBar1.ValueChanged

If ListBox1.TopIndex <> 0
ThenListBox1.TopIndex = ListBox1.TopIndex - 1

End
If

End
Sub

Merci

6 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 juin 2009 à 10:02
    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
        Static iOldValue As Integer
        With ListBox1
            If iOldValue < VScrollBar1.Value Then
                'on descend
                .TopIndex += 1
            Else
                'on monte
                .TopIndex -= 1
            End If
            iOldValue = VScrollBar1.Value
        End With
    End Sub

<!-- Coloration syntaxique vb/vba/vb.net : http://charles.racaud.free.fr/code-syntaxing/ -->
Coloration syntaxique vb/vba/vb.net
3
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 juin 2009 à 15:34
topindex le gère très bien tout seul non ?

je n'ai eu aucun erreur en tout cas

ps : ta construction du IF n'est pas tiptop...
il n'y a aucun intérêt à faire
SI CONDITION
QUITTER
SINON
ACTION

tu devrais juste faire
SI PAS CONDITION
ACTION

++


<hr size="2" width="100%" />
Prenez un instant pour répondre à [sujet-SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp 
3
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 juin 2009 à 08:55
salut,

il faut tenir compte de l'ancienne valeur de la vscroll pour savoir si elle a été montée ou descendue, pour ajouter ou soustraire 1
0
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013
1 juin 2009 à 09:44
Salut,

Je ne vois pas comment faire

merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013
1 juin 2009 à 10:24
Merci et à plus !!!
0
KIPRE74 Messages postés 120 Date d'inscription jeudi 15 mai 2008 Statut Membre Dernière intervention 21 novembre 2013
1 juin 2009 à 15:13
Petite gestion des exceptions

 Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll 

 Static iOldValue 
As Integer

With
lstEsp





If

iOldValue < VScrollBar1.Value Then





If

lstEsp.TopIndex + 1 >= lstEsp.Items.Count - 1 Then





Exit



Sub







Else








'on descend






.TopIndex += 1






End



If







Else








If

lstEsp.TopIndex - 1 <= 0 Then





Exit



Sub







Else








'on monte






.TopIndex -= 1






End



If







End



If





iOldValue = VScrollBar1.Value






End



With



End Sub
0
Rejoignez-nous