Probleme de transfere d'une listebox a une autre
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Private Sub TransfertListe(ByVal L1 As ListBox, ByVal L2 As ListBox)
Dim Item As Object
Dim I As Integer
'Ajouter les éléments sélectionnés dans L1 à L2
For Each Item In L1.SelectedItems
L2.Items.Add(Item)
Next
'Supprimer les éléments sélectionnés dans L1
'en commençant par le dernier élément.
For I = L1.SelectedIndices.Count - 1 To 0 Step -1
L1.Items.RemoveAt(L1.SelectedIndices(I))
Next
AfficherNbrElements(L1, L2)
End Sub |
L'erreur intervient a la ligne 13 : "Impossible de modifier la collection d'éléments lorsque la propriété DataSource est définie."
Effectivement voici comment se remplie ma liste box :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Dim MyCommand1 As SqlCommand = MyConnexion.createCommand()
Dim strsql As String
strsql = "SELECT [NumV],[DescrV] FROM [PPE6_G1].[dbo].[Vaccin];"
MyCommand1.CommandText = strsql
Dim myreader1 As SqlDataReader = MyCommand1.ExecuteReader()
Dim dt As New DataTable
dt.Columns.Add("Num")
dt.Columns.Add("Descript")
Do While myreader1.Read
Dim v1 = myreader1.Item(0)
Dim v2 As String = myreader1.GetString(1)
dt.Rows.Add(v1, v2)
Loop
myreader1.Close()
LtBVaccin.DataSource = dt
LtBVaccin.DisplayMember = "Descript"
myreader1.Close() |
Et apres avoir transferer les items d'un box a un autre je veux les inserer :
Pour chaque item dans la liste :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| Dim requete1 As SqlCommand = MyConnexion.CreateCommand()
requete1.CommandText = " select max(NumPers) from Personne;"
Dim nb As Integer = requete1.ExecuteScalar()
Dim requete2 As SqlCommand = MyConnexion.CreateCommand()
Dim dv As DataRowView = CType(Me.LtBVaccinChoix.SelectedItem, DataRowView)
Dim strsql As String
For Each Vaccin As Integer In LtBVaccinChoix.Items
strsql = "INSERT INTO Necessiter(NPays_Pays,NumV_Vaccin) VALUES(" & nb & "," & Vaccin & ");"
requete2.CommandText = strsql
Dim reultat = requete2.ExecuteScalar()
Next |