listbox event lost

G

Guest

I have a form with a DeptList, an EmployeeList and a panel containing a bunch
of textboxes for employee data, e.g. name, address, etc. The textboxes are
bound to a datatable in a dataset. The DeptList SelectedIndexChanged event
handler is used to populate the employeeList and its SelectedIndexChanged
event handler is used to populate the textboxes. I also have added a handler
for the DataColumnChanged event of the datatable
Private sub OnColChanged(..)
m_bDirty = true
end sub
and a handler for the panel validating event
private sub DataPanel_Validating(..)
if m_bDirty then
QuerySave ( this uses a msgbox to query the user)
end if
end sub

I now select an employee, enter some data in the text boxes and then click
an unselectd row in the DeptList. With the code in the validating handler
commented out, the DeptList SelectedIndexChanged event is raised and
everything works as expected. With the code include however, the DeptList
SelectedIndexChanged event either wasn't raised in the first place or was
surpressed because the event handler is not called. In fact even with the
code commented out, if I place a debup break point on the End Sub, the
SelectedIndexChanged is not called. Of course since the SelectedIndexChanged
is not called, nothing works correctly. The problem seems to be related to
the listbox because if I click a btn outside the panel everything works as
expected. The list box shows the correct line selected in either case. The
same behavior occurs if I put a breakpoint on the end sub of the OnColChanged
event handler, so that if I change some data and then click the list box, the
execution breaks in the OnColChanged handler and afterwards the
SelectedIndexChanged is not called. How do I get around this problem? Is
there some way to re-raise the pending events for the listbox?
 
G

Guest

I tried a few more ideas without getting anywhere. If I put
Application.DoEvents as the first line in the panel validating handler, it
doesn't change anything. If I put MsgBox("test") as the only line in the
validating handler, when I click the msg box ok, the listbox has captured the
mouse and the SelectedIndexChanged handler does not get called unless I click
on the list box a second time. I also tried using listbox click event with
the same result as before. It doesn't get called. I expect that the problem
is connected with something else grabbing the focus just after a listbox is
click which for some reason eats all the pending events or pervents them from
being raised.
 
G

Guest

I have found a workaround for this issue by using a timer. I initialize a
shared member variable with the Me pointer and then set a timer in the
Validating event handler. In the timer event handler I use the shared Me to
hand the call back to the form. The problem with this approach is that in
the meantime the DeptList SelectedindexChanged code has been off and running
before I really wanted it to. The required setting some flags to suspend
processing at some point which the QuerySave code then restarts after it has
done its thing. I would still like to know about the root problem here of
why the listbox events are not being raised or are disappearing somewhere.
As mentioned before, just setting a break point in the Validating event will
cause the listbox to loose its way.
 

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

Top