473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to clear comboBoxes

Is there an easier way to clear all of the comboBoxes on my form? I am
currently using this code...

autoCompleteComboBox1.Text="";
autoCompleteComboBox1.SelectedText="";

autoCompleteComboBox2.Text="";
autoCompleteComboBox2.SelectedText="";

autoCompleteComboBox3.Text="";
autoCompleteComboBox3.SelectedText="";

autoCompleteComboBox4.Text="";
autoCompleteComboBox4.SelectedText="";

autoCompleteComboBox5.Text="";
autoCompleteComboBox5.SelectedText="";

autoCompleteComboBox6.Text="";
autoCompleteComboBox6.SelectedText="";
.....But it would be nice if I could do something like this:

AllControls.Clear;
Nov 16 '05 #1
4 2720
Sorry, this is in VB code and I don't know the for each equivalent off the
top of my head.

For Each ctl In Form.Controls
If TypeOf ctl Is ComboBox Then
ct1.Text = ""
ct1.SelectedText = ""
End If
Next

"Keith Smith" <ke*********@verizon.net> wrote in message
news:eyrOd.22893$uc.16994@trnddc09...
Is there an easier way to clear all of the comboBoxes on my form? I am
currently using this code...

autoCompleteComboBox1.Text="";
autoCompleteComboBox1.SelectedText="";

autoCompleteComboBox2.Text="";
autoCompleteComboBox2.SelectedText="";

autoCompleteComboBox3.Text="";
autoCompleteComboBox3.SelectedText="";

autoCompleteComboBox4.Text="";
autoCompleteComboBox4.SelectedText="";

autoCompleteComboBox5.Text="";
autoCompleteComboBox5.SelectedText="";

autoCompleteComboBox6.Text="";
autoCompleteComboBox6.SelectedText="";
....But it would be nice if I could do something like this:

AllControls.Clear;

Nov 16 '05 #2
[In VB:]
For Each ctl In Form.Controls
If TypeOf ctl Is ComboBox Then
ct1.Text = ""
ct1.SelectedText = ""
End If
Next


I have tried but can't seem to find the proper C# code. The closest I can
come up with is...

foreach(Control x in Form1)
{
}

Which obviously is not complete. Any ideas?
Nov 16 '05 #3
"Keith Smith" <ke*********@verizon.net> wrote:
foreach(Control x in Form1)


How about this?

foreach (Control c in Form1.Controls)
{
if (c is ComboBox) { c.Clear(); }
}

(The Clear method actually removes all the items from the list. You
might just want to clear the Text property. Obviously, you can do what
you like with c inside that block.)

P.
Nov 16 '05 #4
Uh, so I need to check my code before I post it!

foreach (Control c in this.Controls)
{
if (c is ComboBox)
{
((ComboBox) c).Items.Clear(); // or .Text = "", or whatever
}
}

P.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: stingrays | last post by:
Below is my code for a combobox. Basically, I have 2 comboboxes. 1 box is the application selection and the other retrieves data from the dataset (SQL Server) to populate the drop down in the...
4
by: Kathy | last post by:
In my custom menu one menu item opens a form to add new Makes to TblMakes and another menu item opens a form to add new Models to TblModels. I have a form that has a combobox for Makes and a...
0
by: johnson_cy | last post by:
I am using Access 2000. My main form has a record source of a table (employeeTbl with key of . It is filtering the record results. My subform and mainform have the link child/link master set...
1
by: Craig G | last post by:
for months we have been dabling round looking at various 3rd party comboboxes that allow the user to type text into the combobox as a search mechanism what we've found is that the likes of...
13
by: KKuser | last post by:
Hello: I have 20, 30 text and combo boxes on one form, and I would like to clear them up at one time using the statement "With..........End With". I used this when using VB6, but I don't know...
5
by: Jason Huang | last post by:
Hi, In my C# Windows Form MyForm, it has many TextBoxes, e.g., txtName, txtID, txtAddress, ..., it also has many ComboBoxes, e.g., cboState, cboGender. How do I clear all those controls's Text...
2
by: Matt | last post by:
Hi all, me again! :) I've now got an issue with combo boxes. Basically, I have a number of items that I want a user to pick from a single list. It's basically along the lines of: Fruit 1: ...
2
by: Wingot | last post by:
Hey, I have a view to a database that I have created for Client Maintenance. It has a number of fields, but the important ones are Medical Condition, Bill To, and Country. I have a couple of...
5
aas4mis
by: aas4mis | last post by:
I haven't had much luck with specific controls, their properties and loops in the past. I thought I would share this tidbit of code, feel free to modify/modularize in any way to suit your needs. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.