Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-25-2009, 04:59 AM
Lennie Lennie is offline
Registered User
 
Join Date: Jan 2005
Location: New Zealand
Posts: 201
Visual C# Net 2003 , Clear textBox problem

Hi there,
I am a newbie to using Visual C# Net 2003. I am having problem trying to clear all the textbox using FOREACH command structure. In VB6 there was no problem but in C# I do not know how to write the script. Please help me.

Here is the sample of the VB6 version. My boss wants similar events. Private Function FCleartextBox()
Dim ctl As Object
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl.text = ""
End If
Next
End Function
-----------------------------------
C# version tried by me.
Private void FClearTextBox()
{
control ctl = textbox;
foreach ctl in this.controls
{
if typeof ctl is textbox
{
ctl.text = ""
}
}
}
__________________
Cheers,
Lennie
Reply With Quote
  #2  
Old 10-25-2009, 10:09 AM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
This is a very un-OOP approach. However, if you insist, you can use the typeid() operator to detect the type of an object or better yet, use the safer dynamic_cast operator to detect whether the object is of the desired type.
In proper C++ programming, you would rarely do such things. Instead, a class hierarchy with overridden virtual functions will do the trick.
__________________
Danny Kalev
Reply With Quote
  #3  
Old 10-25-2009, 07:46 PM
Lennie Lennie is offline
Registered User
 
Join Date: Jan 2005
Location: New Zealand
Posts: 201
Hi Danny,
Thank you for your reply. I did not insist of using the VB6 way of clearing the textbox. As I have mentioned I am new to Visual C# Net 2003. In the OOP approach, could you please share with me sample script.
__________________
Cheers,
Lennie
Reply With Quote
  #4  
Old 10-26-2009, 01:06 AM
Lennie Lennie is offline
Registered User
 
Join Date: Jan 2005
Location: New Zealand
Posts: 201
Hi there,
I have tried out this script and it's working. Would like to share this with all Visual C# Net 2003 Newbies just like me. This script main event is to clear all textbox in a Form.
Code:
using System.Text;
using System.Collections;

private void FClearTextBox()
{
    foreach ( Control ctl in this.Controls)
           {
               if (ctl.GetType == typeof (TextBox))
                    {
                         ctl.Text = "";
                    }
           }
}
Good Luck and Enjoy yourself.

Have a Good Day.
__________________
Cheers,
Lennie

Last edited by Hack; 10-27-2009 at 12:58 PM. Reason: Added Code Tags
Reply With Quote
  #5  
Old 10-30-2009, 05:40 AM
Lennie Lennie is offline
Registered User
 
Join Date: Jan 2005
Location: New Zealand
Posts: 201
Hi all Helper,
Thank you very much for helping me. My script for clearing all the TextBox is now working.
Listed below is the working script to save with other Newbies having the samme problem.
Enjoy yourself.
Code:
	private void FClearTextBox ()	
			// clear all input textbox
		{		
			foreach ( Control ctl in this.Controls )
			{
				if ( ctl.GetType() == typeof(TextBox))
				{
					ctl.Text = "";
				}
			}		 
		 
			 
		}  // End
__________________
Cheers,
Lennie

Last edited by Hack; 10-30-2009 at 08:38 AM. Reason: Added Code Tags
Reply With Quote
  #6  
Old 10-30-2009, 08:39 AM
Hack's Avatar
Hack Hack is offline
Super Moderator
 
Join Date: Apr 2007
Location: Sterling Heights, Michigan
Posts: 7,719
Just a quick note...please use [code]your code goes here[/code] tags - it just makes things so much easier to read. :)
__________________
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista

Microsoft MVP 2005/2006/2007/2008/2009
Reply With Quote
  #7  
Old 10-30-2009, 06:05 PM
Lennie Lennie is offline
Registered User
 
Join Date: Jan 2005
Location: New Zealand
Posts: 201
Hi Hack,
Nice hearing from you again. It has been quite a while. I have edited the block of script I have posted here to share with other C#Net 2003 Newbie using your suggestion of
I am not sure whether to use it on individual line or from before the Start and at the End of the block of script.

Thanks you for your help.
__________________
Cheers,
Lennie
Reply With Quote
  #8  
Old 11-03-2009, 08:59 AM
Hack's Avatar
Hack Hack is offline
Super Moderator
 
Join Date: Apr 2007
Location: Sterling Heights, Michigan
Posts: 7,719
Quote:
Originally Posted by Lennie View Post
before the Start and at the End of the block of script.
Yes...
__________________
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista

Microsoft MVP 2005/2006/2007/2008/2009
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Applications Consultant (Microsoft NET, Interwoven, and Visual Basic 6) Branta Careers 0 06-29-2005 05:30 PM
TierDeveloper Full-Integration with Microsoft Visual Studio .NET 2003 IDE Zahid Iqbal dotnet.announcements 0 05-20-2003 08:06 AM
Typing in layered textbox problem AJ Web 0 03-12-2002 03:55 PM
YAG's status report - Feb 14, 2002 Seth Grossman [MSFT] .NET 1 02-15-2002 01:35 AM
Clear Textbox Forchat Web 1 01-26-2001 11:47 AM


All times are GMT -4. The time now is 10:32 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.