BeginUpdate doesn't work in Listbox

  • Thread starter Thread starter Anil Gupte
  • Start date Start date
A

Anil Gupte

I am using the following code:

URLListBox.BeginUpdate()
URLListBox.DataSource = DSContent '.Tables("ContentSites")
URLListBox.DisplayMember = "ContentSites.SiteName"
URLListBox.ValueMember = "ContentSites.URL"
URLListBox.EndUpdate()
The program execution insistis on going to the Sub
URLListBox_SelectedIndexChanged after the 2nd line (URLListBox.DataSource
=...) It does this for each item in the DataSet. Isn't this exactly what
BeginUpdate is supposed to prevent?

Thanx,
 
Anil Gupte said:
I am using the following code:

URLListBox.BeginUpdate()
URLListBox.DataSource = DSContent '.Tables("ContentSites")
URLListBox.DisplayMember = "ContentSites.SiteName"
URLListBox.ValueMember = "ContentSites.URL"
URLListBox.EndUpdate()
The program execution insistis on going to the Sub
URLListBox_SelectedIndexChanged after the 2nd line
(URLListBox.DataSource =...) It does this for each item in the
DataSet. Isn't this exactly what BeginUpdate is supposed to
prevent?

No, it has nothing to do with events. It only defines whether the view
is immediatelly refreshed as soon as the listbox' content changes. This
is because doing a lot of consequtive operations affecting the view
would cause a refresh after each operation. This costs performance.
To avoid this, you can suppress the refresh by calling beginupdate, do
the operations, and call Endupdate afterwards. This makes the listbox
refresh only once, at EndUpdate, after all operations have been done.

Armin
 
So how do I prevent the code execution from going to the
_SelectedIndexChanged when I am populating the listbox?

Thanx for your help.
 
Anil Gupte said:
So how do I prevent the code execution from going to the
_SelectedIndexChanged when I am populating the listbox?

I don't know, I don't use data binding. I'd set a flag before filling
the listbox and clear it afterwards. In the event handler, immediatelly
exit the procedure if the flag is set.


Armin
 
RemoveHandler URLListBox.SelectedIndexChanged, AddressOf
URLListBox_SelectedIndexChanged
URLListBox.DisplayMember = "ContentSites.SiteName"
URLListBox.ValueMember = "ContentSites.URL"
URLListBox.DataSource = DSContent '.Tables("ContentSites")
AddHandler URLListBox.SelectedIndexChanged, AddressOf
URLListBox_SelectedIndexChanged
 
Back
Top