Resetting combo boxes

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
 
G

Guest

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?
 
G

Guest

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
 
G

Guest

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.
 
R

RobinS

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.
-------------------------------
 
G

Guest

Robin,

No such property in Access. I will try thier group directly.

Thanks just the same.
 

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

Similar Threads


Top