Weird Listbox Behavior

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

I have a bound listbox on a form. The listobx is bound to a single
column table that contains a list of employees. The listbox's
selection mode is set to MultiSimple. When the form loads, the top
item is selected by default.

What is weird is that whenever I change the selections (e.g. add
another one, deselect the first one, whatever), any code that I have
associated with this listbox will not run. I created a simple example
to try to figure out what is going on, but I am clueless:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox("code is running properly")
Dim drvListItem As DataRowView
For Each drvListItem In lbxEmps.SelectedItems
MessageBox.Show(drvListItem(lbxEmps.DisplayMember))
Next
End Sub

If I load the form and click this button immediately, it runs fine,
displaying two messageboxes (the first with my text and the second
with item 0). However, if I make any selection changes to the box and
then click the button, nothing happens. Nothing, that is, except that
all code is suspended and I have to break the execution in the
debugger.

I'm mystified. Can anybody help?

Thanks,
Randy
 
Randy,

Why are you accessing the binded data in a control using that Conrol, while
you have the data direct accessible in the datasource of that. In my idea a
very bad way of programming.

Cor
 
How do you determine which rows are selected in the control by looking
at the datasource?
 
:Jack,

Sorry, I have readethe text in another way then intended by you.

Most problems with the databinded listbox and combobox (listcontrols)
becomes because that there is somewhere some code that creates an infinity
loop.

That is by instance because that the changing of the datasource does set the
changeevent of the listbox. If you then creates there again something, then
it is fired again and again and again................................


Have a look if you have such a kind of thing in an event.

Cor
 
Back
Top