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
| Option Explicit
Private EnableEvents As Boolean
Private Sub CommandButton1_Click()
Dim i As Byte, rep As Integer
rep = vbNo
If ListBox1.ListIndex <> -1 Then rep = MsgBox("Voulez-vous modifier la ligne sélectionnée?", vbYesNo + vbQuestion)
If rep = vbNo Then
ListBox1.AddItem TextBox1
For i = 1 To 4
ListBox1.List(ListBox1.ListCount - 1, i) = Me.Controls("TextBox" & i + 1)
Me.Controls("TextBox" & i) = ""
Next
TextBox5 = ""
TextBox1.SetFocus
Else
EnableEvents = True
For i = 0 To 4
ListBox1.List(ListBox1.ListIndex, i) = Me.Controls("TextBox" & i + 1)
Me.Controls("TextBox" & i + 1) = ""
Next
TextBox5 = ""
TextBox1.SetFocus
EnableEvents = False
ListBox1.ListIndex = -1
End If
End Sub
Private Sub ListBox1_Click()
Dim i As Byte
If ListBox1.ListIndex = -1 Or EnableEvents Then Exit Sub
For i = 0 To 4
Me.Controls("TextBox" & i + 1) = ListBox1.List(ListBox1.ListIndex, i)
Next
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim rep As Integer
If ListBox1.ListIndex = -1 Then Exit Sub
rep = MsgBox("Voulez-vous supprimer la ligne sélectionnée?", vbYesNo + vbQuestion)
If rep = vbYes Then
ListBox1.RemoveItem (ListBox1.ListIndex)
End If
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
CommandButton1.SetFocus
End Sub
Private Sub UserForm_Activate()
Dim i&, ArrCol
TextBox1.SetFocus
ListBox1.ColumnCount = 5
ListBox1.ColumnWidths = "50;50;120;40;80"
ArrCol = Array(0, 50, 100, 220, 260)
For i = 1 To 5
Me.Controls("TextBox" & i).Width = Split(Replace(ListBox1.ColumnWidths, " pt", ""), ";")(i - 1)
Me.Controls("TextBox" & i).Left = ArrCol(i - 1) + ListBox1.Left
Next i
ListBox1.Width = 345
CommandButton1.Move TextBox5.Left + TextBox5.Width, TextBox5.Top
End Sub |
Partager