|
-
Oct 19th, 2002, 12:27 PM
#1
Thread Starter
Frenzied Member
Stop SelectedIndexChanged, Selectedvaluechanged ... being called during form load
Look at the following code:
private sub listboxbind()
ListBox1.DataSource = tb1
ListBox1.DisplayMember = "name"
ListBox1.ValueMember = "ID" ' data type is integer
End Sub
Private Sub ListBox1_SelectedvalueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
MsgBox(sender.selectedvalue.ToString)
End Sub
Private Sub bindfrm(ByVal i As Integer)
'some code here
End Sub
During the form load the Listbox1_selectevalueChanged is called about 7 times, and the messagebox shows 'System.Data.DataRowView' 6 times and the selectedvalue (a number) for the last time. Well this may not seem important at first, but if i change the above like this:
Private Sub ListBox1_SelectedvalueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged
MsgBox(sender.selectedvalue.ToString)
bindform(sender.selectedvalue)
End Sub
then after 4 times it stops with an error in the bindfrm sub:
Cast from type 'DataRowView' to type 'Integer' is not valid.
Ok, the reason is obvious, I am calling a sub that needs an integer parameter with a DataRowView.
BUT
The problem is this: how can i stop this event being called during the form load? Each change you make to the listbox for example setting its datasourse, display member... calls this once or twice!!!. This is true for comboboxes too, but there you have an event called 'selectionchangecommitted' that is not called, so I used that in such cases but for the list box there is no such an event.
I hope I have conveyed what I mean.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|