Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_To1From2.Click, Button_To2From1.Click Dim L_IN As New ListBox Dim L_DE As New ListBox Dim V_ListItemAry_IN() As String Dim V_ListItemAry_DE() As String Select Case CType(sender, Button).Name Case Button_To1From2.Name L_IN = ListBox1 L_DE = ListBox2 Case Button_To2From1.Name L_IN = ListBox2 L_DE = ListBox1 End Select
If L_DE.Items.Count > 0 And L_DE.SelectedItems.Count > 0 Then For Each V_ListItem_DE As Object In L_DE.SelectedItems V_ListItemAry_DE = Split(V_ListItem_DE.ToString, ":") If L_IN.Items.Count = 0 Then L_IN.Items.Add(V_ListItem_DE.ToString) Else For i As Integer = 0 To L_IN.Items.Count - 1 V_ListItemAry_IN = Split(L_IN.Items(i), ":") If V_ListItemAry_DE(0) < V_ListItemAry_IN(0) Then If i = 0 Then L_IN.Items.Insert(0, V_ListItem_DE.ToString) Exit For End If ElseIf V_ListItemAry_DE(0) > V_ListItemAry_IN(0) Then If i = L_IN.Items.Count - 1 Then L_IN.Items.Add(V_ListItem_DE.ToString) Else L_IN.Items.Insert(i + 1, V_ListItem_DE.ToString) Exit For End If End If Next End If L_DE.Items.Remove(V_ListItem_DE.ToString) Next End If
分類:[その他]
以下のコードで2つのlistbox間の値の移動を移動をしていますが
L_DE.Items.Remove(V_ListItem_DE.ToString)
のところで「この列挙子がバインドされている一覧は変更されています。
列挙子は、一覧が変更しない場合に限り使用できます。」エラーに
なります。原因を教えて下さい。
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_To1From2.Click, Button_To2From1.Click
Dim L_IN As New ListBox
Dim L_DE As New ListBox
Dim V_ListItemAry_IN() As String
Dim V_ListItemAry_DE() As String
Select Case CType(sender, Button).Name
Case Button_To1From2.Name
L_IN = ListBox1
L_DE = ListBox2
Case Button_To2From1.Name
L_IN = ListBox2
L_DE = ListBox1
End Select
If L_DE.Items.Count > 0 And L_DE.SelectedItems.Count > 0 Then
For Each V_ListItem_DE As Object In L_DE.SelectedItems
V_ListItemAry_DE = Split(V_ListItem_DE.ToString, ":")
If L_IN.Items.Count = 0 Then
L_IN.Items.Add(V_ListItem_DE.ToString)
Else
For i As Integer = 0 To L_IN.Items.Count - 1
V_ListItemAry_IN = Split(L_IN.Items(i), ":")
If V_ListItemAry_DE(0) < V_ListItemAry_IN(0) Then
If i = 0 Then
L_IN.Items.Insert(0, V_ListItem_DE.ToString)
Exit For
End If
ElseIf V_ListItemAry_DE(0) > V_ListItemAry_IN(0) Then
If i = L_IN.Items.Count - 1 Then
L_IN.Items.Add(V_ListItem_DE.ToString)
Else
L_IN.Items.Insert(i + 1, V_ListItem_DE.ToString)
Exit For
End If
End If
Next
End If
L_DE.Items.Remove(V_ListItem_DE.ToString)
Next
End If
End Sub