Data-bound listbox prevents other controls from handling events!

R

Rob Richardson

Greetings!

I am struggling to understand data binding in VB.Net, and it's slow
going.

I have a list box bound to a dataset that is filled from a SQL Server
table. In addition to the list box, I have two buttons on the form.
When I click one, a data adapter's Fill() method gets data into the
table, and the column the list box is bound to obligingly appears in
the list box. The other button merely displays a message box when it
is clicked.

If I click the first button, wait for the list box to fill, and then
click the second button without doing anything in the list box, the
message box appears. I can also click the X in the upper right corner
of the form, and the form will close. But if I click in the list box
to select a different record in the table and then click on the second
button, the button appears to be depressed as usual, but the message
box does not appear! The same thing happens with the X. Its
appearance changes as expected when I click on it, but the form stays
open.

The data objects were all created by dragging them from the Server
Explorer onto the form and configured with their appropriate
designers. The only code I wrote was a single line to call Fill() and
another line to call MessageBox.Show().

Why is the list box being so selfish?


The task I was trying to do when I saw this behavior was to get a
second control to change when I selected a new record in the list box.
I dropped a text box onto the form and bound it to one of the columns
in the same dataset and table the list box was bound to. I wanted to
see the contents of that text box change when a different record was
selected in the list box. It didn't happen. What do I have to do to
get that to happen?

Thanks very much!

Rob
 
C

Cor Ligthert

Rob,

I cannot get really behind what you write, however the combobox and the
listbox (both inherit listcontrol) have the nasty behaviour that they fires
events when the datasource is loaded.

To prevent that is the easiest thing to do to use a switch as datasource
loaded on the place where you are sure that is done.

Than use in your selection index change event check that event as start.
If EverythingIsLoadedSwitch then
.........
End if

I hope this helps and otherwise you can show some code to show us what your
problem can be?

Cor
 
R

Rob Richardson

Cor,

I am sorry, but I can't show you code. There isn't any! The whole
project was set up using the IDE and dragging objects from the toolbox
onto the form.

I tried setting the exact same controls bound to the exact same table,
but creating the bindings at run time instead of design time. No
problem!

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top