Bonjour à tous,

j'ai ce code actuellement qui me permet de créer des boutons dynamiquement gràce à une base de données.

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
 
For Each oDataRow In oDataTable.Rows
                obutton = New Button
                obutton.Left = 10
                obutton.Top = 10 + (100 * Panel1.Controls.Count)
                obutton.BackgroundImage = My.Resources.user
                obutton.BackgroundImageLayout = ImageLayout.Stretch
                obutton.BackColor = Color.Transparent
                obutton.BackgroundImageLayout = ImageLayout.Stretch
                obutton.FlatStyle = FlatStyle.Standard
                obutton.Height = 100
                obutton.Width = 105
                obutton.Name = "btn" & i.ToString
                obutton.Text = oDataTable.Rows(i).Item("uti_nom").ToString
                AddHandler obutton.Click, AddressOf utilisateurSelectionne
                Me.Panel1.Controls.Add(obutton)
                i += 1
            Next
 
Private Sub utilisateurSelectionne(ByVal sender As Object, ByVal e As System.EventArgs) Handles obutton.Click
msgbox(sender.tostring)
    End Sub
Mais en fait il me crée mes 2 boutons, jusque la pas de problemes mais quand je clique sur le 2e bouton, il m'affiche 2 msgbox alors qu'il m'en affiche qu'un quand je clique sur le 1er. et je ne vois pas pourquoi.

Cordialement

Cédric Daniel