A
afh3
Re: Windows Forms ListBox Binding and SelectedIndexChanged Event firings.
It would appear that the process of binding a ListBox to a DataSource and
setting the DisplayMember and ValueMember properties results in the
SelectedIndexChanged event firing for each of the property settings.
How remarkably annoying is that?
Private Sub btnGetImageList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGetImageList.Click
Dim myDataTable As localhost.dsImageList.ImagesDataTable
myDataTable = mywebsvc.GetImageList.Images.Copy
ListBox1.DataSource = myDataTable
ListBox1.ValueMember = myDataTable.Image_IDColumn.ToString
ListBox1.DisplayMember = myDataTable.Image_NameColumn.ToString
ListBox1.SelectedIndex = -1
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim myImageBytes() As Byte = mywebsvc.GetImage(ListBox1.SelectedValue)
Dim myStream As New System.IO.MemoryStream(myImageBytes, 0,
myImageBytes.Length - 1)
Dim myImage As Image
pictDisplayImage.Image = myImage.FromStream(myStream)
End Sub
In the code above, the ListBox1_SelectedIndexChanged event fires for >each<
of the property settings in the button click event -- in addition to the one
I was expecting, where I set the SelectedIndex to -1. The SelectedIndex
value during all of the totally uncalled-for event firings is zero -- a
valid value for the index of a list member, which makes trapping it
remarkably inconvenient. Also, it seems to me that since the value at the
mis-fired events is always zero, it hasn't really changed, has it? Doesn't
that sort of defy the whole concept of the name of the event?
What's up with this? Let me guess....I see an answer...It's coming to
me...."Wait for Whidbey"
-afh3
Sorry for the tone. It's late and I'm p.o.'ed that I've wasted an hour on
this issue.
It would appear that the process of binding a ListBox to a DataSource and
setting the DisplayMember and ValueMember properties results in the
SelectedIndexChanged event firing for each of the property settings.
How remarkably annoying is that?
Private Sub btnGetImageList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGetImageList.Click
Dim myDataTable As localhost.dsImageList.ImagesDataTable
myDataTable = mywebsvc.GetImageList.Images.Copy
ListBox1.DataSource = myDataTable
ListBox1.ValueMember = myDataTable.Image_IDColumn.ToString
ListBox1.DisplayMember = myDataTable.Image_NameColumn.ToString
ListBox1.SelectedIndex = -1
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim myImageBytes() As Byte = mywebsvc.GetImage(ListBox1.SelectedValue)
Dim myStream As New System.IO.MemoryStream(myImageBytes, 0,
myImageBytes.Length - 1)
Dim myImage As Image
pictDisplayImage.Image = myImage.FromStream(myStream)
End Sub
In the code above, the ListBox1_SelectedIndexChanged event fires for >each<
of the property settings in the button click event -- in addition to the one
I was expecting, where I set the SelectedIndex to -1. The SelectedIndex
value during all of the totally uncalled-for event firings is zero -- a
valid value for the index of a list member, which makes trapping it
remarkably inconvenient. Also, it seems to me that since the value at the
mis-fired events is always zero, it hasn't really changed, has it? Doesn't
that sort of defy the whole concept of the name of the event?
What's up with this? Let me guess....I see an answer...It's coming to
me...."Wait for Whidbey"
-afh3
Sorry for the tone. It's late and I'm p.o.'ed that I've wasted an hour on
this issue.