M
Martin
I have an unbound Listbox which is filled with ListItems. MultiSelect is set
to true. However, if the ListItems do not have unique text/value pairs, then
if a multi-selection is done, the Selected properties of the ListItems are
not set correctly.
Is this expected behaviour?
As an example, take the MSDN example at
http://msdn.microsoft.com/library/d...rfSystemWebUIWebControlsListBoxClassTopic.asp
and then change the text of the listitems, so they are not unique. The
multi-select will then not work as expected.
Or take my own example which require you to drag a Listbox and a button on a
web form. Set the selection mode to multiple and Copy/paste the following
eventhandlers to the vb page:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Me.IsPostBack Then
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("three", "3"))
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("three", "3"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("two", "2"))
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Delete selected items
Dim SelItems As New ArrayList
Dim li As ListItem
For Each li In ListBox1.Items
If li.Selected Then SelItems.Add(li)
Next
For Each li In SelItems
ListBox1.Items.Remove(li)
Next
End Sub
to true. However, if the ListItems do not have unique text/value pairs, then
if a multi-selection is done, the Selected properties of the ListItems are
not set correctly.
Is this expected behaviour?
As an example, take the MSDN example at
http://msdn.microsoft.com/library/d...rfSystemWebUIWebControlsListBoxClassTopic.asp
and then change the text of the listitems, so they are not unique. The
multi-select will then not work as expected.
Or take my own example which require you to drag a Listbox and a button on a
web form. Set the selection mode to multiple and Copy/paste the following
eventhandlers to the vb page:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Me.IsPostBack Then
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("three", "3"))
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("one", "1"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("three", "3"))
ListBox1.Items.Add(New ListItem("two", "2"))
ListBox1.Items.Add(New ListItem("two", "2"))
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Delete selected items
Dim SelItems As New ArrayList
Dim li As ListItem
For Each li In ListBox1.Items
If li.Selected Then SelItems.Add(li)
Next
For Each li In SelItems
ListBox1.Items.Remove(li)
Next
End Sub