|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 = "";
}
}
}
Have a Good Day.
__________________
Cheers, Lennie Last edited by Hack; 10-27-2009 at 12:58 PM. Reason: Added Code Tags |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
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 |
|
#8
|
||||
|
||||
|
__________________
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |