ComboBox を継承するクラスがあります。
List(of String) を受け取り、Items コレクションを同じ値に設定するプロパティがあります。ただし、アイテム リストをクリアしても、常にクリアされるわけではありません。
Set(ByVal value As System.Collections.Generic.List(Of String))
MyBase.Items.Clear()
If MyBase.Items.Count <> 0 Then
'Shouldn't ever get here
Throw New Exception
End If
For Each item As String In value
If item Is Nothing Then
Items.Add(String.Empty)
Else
Items.Add(item)
End If
Next
End Set
何が起こっているのか、誰にも考えがありますか?
編集:
変数の内容を確認できるようにコードを変更しました。
Set(ByVal value As System.Collections.Generic.List(Of String))
Debug.WriteLine("values passed to property: " & Join(value.ToArray, ", "))
Dim itemvalues As String = String.Empty
For Each item As String In Items
itemvalues &= item & ", "
Next
Debug.WriteLine("items in combobox: " & itemvalues)
Items.Clear()
If Items.Count <> 0 Then
'Shouldn't ever get here
Throw New Exception
End If
For Each item As String In value
If item Is Nothing Then
Items.Add(String.Empty)
Else
Items.Add(item)
End If
Next
End Set
そして、これは私が得るものです:
values passed to property: a, c, b
items in combobox:
values passed to property: a, c, b
items in combobox: a, c, b,
values passed to property: a, c, b
items in combobox:
values passed to property: a, c, b
items in combobox: a, c, b,
values passed to property: a, c, b
items in combobox: a, c, b,
values passed to property: a, c, b
items in combobox: a, c, b,
values passed to property: a, c, b
items in combobox: a, c, b,
values passed to property: a, c, b
items in combobox: a, c, b,
debug.writeline の最後のペアの後、クリアに失敗しました