Resetting combo boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, (Winform VS2003)
I have a combo box bound to a typed data set. When the form loads, the
combo box is popluated using a method containing the simple code below:



------------------------
// Fill the datasets for the combo boxes
daDepartment.Fill(dsDepartment.Departments);

// Refresh the combo box
cboDepartment.Refresh();
------------------------------

This works fine, however, once the user has selected a, ummm, selection..
from the combo box, I want the combo box to reset the selection when they hit
the enter button. I use the same method above to do this, however their
selection is reatained & is shown as the current selection.
In other words If there is Selection A, B, C, D. On load the combo box is
set as A. Usr chooses C. After above method is run, I want combo again to
display A. This is not currently happening. C remains.

Hope somwone can shed some light on this seemingly simple problem.
Many thanks in advance.
Ant
 
Use ComboBox.SelectedItem or ComboBox.SelectedIndex to reset the comboBox
selection.

e.g.
cboDepartment.SelectedItem = "My Dept";
or
cboDepartment.SelectedIndex = 0; // 0 = first listitem, -1 = no item is
selected

BTW, do you really need to rebind the data for every 'Enter' key?
 
Hi Tedmond,

Thanks for your advice. I'm using the index to refresh it now as suggested.
Cheers. As for binding with every entry; This was just an attempt at
refreshing the combo boxes. I'll be moving that out of the button now. Thanks
for your advice though.

Much appreciated.
Ant
 
I have been trying to clear combobox settings in Access 2003 w/o success. I
was hoping what you stated here would work but it doesn't. It seens that
Access doesn't support .selectedItem or .SelectedIndex. Am I missing
somingthing?? As I'm really stuck.

I am assinging values to comboboxes either from a query row source or a mix
of user inputs which builds dynamic queries statements from the resultant
entries. The problem arrises when I select a numberic values for one query
and then a text value for the same CB w/o closing the form. I get a message
that the value entered is not valid. The only way I can get the CB to work
correctly again is to close the form and restart it.

Any advise would be greatly appreciated.
 
Try setting combobox.SelectedIndex to -1.

This is a .Net programming newsgroup. If that answer doesn't work, try
posting your question to a Microsoft Access newsgroup.

Robin S.
-------------------------------
 
Back
Top