Databinding a ListBox fires multiple SelectedIndexChanged events

A

Alec MacLean

Hi everyone,

I have a ComboBox that when changed, calls a method to change the content of
a ListBox.
I'm also using the Listbox's SelectedIndexChanged event to change other
control values on the form.

(It's a Company -> People -> Personal Data relationship)

When I bind my datasource to the ListBox, I find that the
SelectedIndexChanged event fires three times.
(I am using BeginUpdate / EndUpdate around the databinding statements.)

This multiple event firing causes the side effect of a form-flicker as the
last set of controls get cleared and set.

Is this normal behaviour for the ListBox when using databinding?

I do want the event to fire, but only after the databinding has completed
and only the one time.

Any help is appreciated.

Alec
 
C

Cor Ligthert [MVP]

Alec,

There can be much reasons and always hard to show in a newsgroup (mostly you
need for that to much code), however prevent your listbox from selecting
when you find any data to it.

The beginupdate and endupdate does nothign in that, so you can do that by
setting a boolean when you do that and test that in the events from the
listbox, or just do removehandler and addhandler from those events what is
the nicest.

I hope this helps,

Cor
 
A

Alec MacLean

Thanks Cor,

I've tried various approaches to resolving this - including your boolean
suggestion, but as yet nothing works quite how I'd like them to.

It's not an essential aspect, just a small tidying of the visual
presentation when the program loads.

Alec
 
C

Cor Ligthert [MVP]

Alec,

If you set it in the load_event, than your form is not yet showed. That is
where I set it normally therefore I probably did not understand you.

Cor
 

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