Question Retriggering a Combo Box

VantiveGuy

Member
Joined
Mar 5, 2009
Messages
18
Location
Brussels on Contract
Programming Experience
1-3
Hi,
I am using a Combo box control to select from a list of Databases, and when one entry is selected I display a listbox of certain objects in the database.
Other controls are then used to filter the list based on either name or content.
Now, I want to know how to Re-load the original list based on the current combo box selection by using a 'Reload' button.
In the button code I am setting focus back to the combo box, but whatever I try I cannot make the list refresh again. I've tried Select, SelectedItem, Text and Find methods but nothing works.
How do I reload the listbox without having to manually use the drop-down and select the same item again?
Thanks for any help.
Al.
 
Update

Hi,

I have found that the following code does what I want it to BUT on;y when I debug and single-step through! Is this a timing issue? I tried DoEvents but even though sngle-stepping through this code cords, it just opens the drop-down when I run. This is the code on the button event.
SelectDatabase.Focus()
Dim sItem As String = SelectDatabase.SelectedItem
SelectDatabase.DroppedDown = True
SelectDatabase.SelectedItem = sItem
Why does this work when stepping through but not when I run it?
Thanks,
Alan.

I guess I should learn to look at the screen when I type.
That line should have said 'Single Stepping through the code works'
 
Fixed!

After much trial and error I found that I could call the ComboBox triggering event directly using :

Call SelectDatabase_SelectedIndexChanged("", e)

Not sure it is it the 'correct' way to do this but it worked great!.

Cheers,
Alan
 
VantiveGuy said:
Call SelectDatabase_SelectedIndexChanged("", e)

Not sure it is it the 'correct' way to do this but it worked great!.
No, it isn't. To change the selected index set the SelectedIndex property, as a result the SelectedIndexChanged event is raised and can be handled by anyone listening for that event.
 
John,
I tried re-setting the SelectedIndex but, as I feared, I didn't trigger the event because the Index hasn't changed.
My code is :
SelectDatabase.Focus()
Dim sIndex As Integer = SelectDatabase.SelectedIndex
SelectDatabase.SelectedIndex = sIndex

It works if I select a different index first, but this just causes the ListBox to load twice, even though it ends up with the correct contents - it looks bad.
 
Fixed

I was given a reality check and found that I had missed the obvious, which was to call aniother method from the combobox event, which I can then call from anywhere else.
Works a treat.
Thanks for the input. Happily, this can be put to bed now :)
 
to call aniother method from the combobox event, which I can then call from anywhere else.
That is an option. You could probably also deselect (-1) and reselect.
point out that I am trying to trigger the same ComboBox entry, so the index remains the same.
That was not clear to me from the initial post.
 
Back
Top