473,383 Members | 1,879 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,383 software developers and data experts.

Addressing specific type of control on a form

How do I cycle through all controls on a form singling
out just textboxes and comboboxes and clearing their text
property? I think I need to address the controls
collection and only clear the text property if the
control is a textbox or a combobox. How do I do this?

Thanks,
John Suru
Nov 20 '05 #1
2 899
jim
Hi John, try using 'typeof':

ex
\\
dim myControl as System.Windows.Forms.Control

For Each myControl in myForm.Controls

if ((typeof myControl is System.Windows.Forms.TextBox) orelse _
(typeof myControl is System.Windows.Forms.Label)) Then

myControl.Text = String.Empty

end if

next
//

code written off the top of my head so watch out for syntax...

hope this helps,

jim

"John Suru" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
How do I cycle through all controls on a form singling
out just textboxes and comboboxes and clearing their text
property? I think I need to address the controls
collection and only clear the text property if the
control is a textbox or a combobox. How do I do this?

Thanks,
John Suru

Nov 20 '05 #2
* "John Suru" <an*******@discussions.microsoft.com> scripsit:
How do I cycle through all controls on a form singling
out just textboxes and comboboxes and clearing their text
property? I think I need to address the controls
collection and only clear the text property if the
control is a textbox or a combobox. How do I do this?


<http://www.mvps.org/dotnet/dotnet/samples/controls/downloads/EnumerateControls.zip>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

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

Similar topics

22
by: Luke | last post by:
Elements with name attribute: form, input, textarea, a, frame, iframe, button, select, map, meta, applet, object, param, img (if you know more reply...) Methods of addresing html elements:...
4
by: the hotshot | last post by:
hello, this seems to be a hard question so far and noone has been able to help with this. is it possible to have access start an autonumber with a prefix according to the year when the data is...
11
by: bill | last post by:
I recently worked with a piece of code where dereferencing the pointer was too slow, and I was able to achieve a nearly 2x speed-up by replacing a local array of size 8 with 8 local variables. (*x...
1
by: Stefan W via .NET 247 | last post by:
I'm relatively new to C#, (I have to use it, now that I'veinherited someone else's projects). I'm looking for a way toiterate through the controls on a form; if the control is of acertain type, I...
3
by: jcrouse | last post by:
I am trying trying to loop through some label controls and setting some properties for the labels I'm looping through. Currently I am addressing the labels one at a time with IF...Then logic, like...
4
by: ABC | last post by:
I want to check the form's controls have or not the specific properties or events. How to determine or gather the properties list under the run-time environment?
6
by: Bob Kochem | last post by:
I am looking for a way via code to access all the menu itmes on a given form. I am looking for something like the Forms or Controls collections, but for menu items. Is there such a thing or method?...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
8
by: Paul Craig | last post by:
Hi, I am currently able to open forms given a string variable using the following code: Dim strForm As String = "Form1" Dim theForm As Form theForm =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.