Changing value of all TextBoxes
-
Hi All, Simple question here (I Hope) I need to reset all my textboxes back to blank and am trying to do it in a nice clean loop. I have the following but it does not work
foreach (TextBox t in this)
{
t.Text = "";
}I am getting the error message
C:\Documents and Settings\gavin\My Documents\Visual Studio Projects\LTBRMaintenance\EditClinic.cs(487): foreach statement cannot operate on variables of type 'LTBRMaintenance.EditClinic' because 'LTBRMaintenance.EditClinic' does not contain a definition for 'GetEnumerator', or it is inaccessible
I have a feeling I am nearly there but am missing something obvious.. Thanks
-
Hi All, Simple question here (I Hope) I need to reset all my textboxes back to blank and am trying to do it in a nice clean loop. I have the following but it does not work
foreach (TextBox t in this)
{
t.Text = "";
}I am getting the error message
C:\Documents and Settings\gavin\My Documents\Visual Studio Projects\LTBRMaintenance\EditClinic.cs(487): foreach statement cannot operate on variables of type 'LTBRMaintenance.EditClinic' because 'LTBRMaintenance.EditClinic' does not contain a definition for 'GetEnumerator', or it is inaccessible
I have a feeling I am nearly there but am missing something obvious.. Thanks
-
I think that this is just an object and doesn't natively expose a GetEnumerator method. Try this: foreach(Control c in this.Controls) { if(c.GetType().ToString()=="System.Windows.Forms.TextBox") c.Text="new vlaue"; } Cheers, Simon X-5 452 rules.
That is exactly it. :) Thanks :)
-
I think that this is just an object and doesn't natively expose a GetEnumerator method. Try this: foreach(Control c in this.Controls) { if(c.GetType().ToString()=="System.Windows.Forms.TextBox") c.Text="new vlaue"; } Cheers, Simon X-5 452 rules.
simons wrote: if(c.GetType().ToString()=="System.Windows.Forms.TextBox") You could also use;
if( c is System.Windows.Forms.TextBox )
this lets the value change for controls derived from TextBox too :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972 -
simons wrote: if(c.GetType().ToString()=="System.Windows.Forms.TextBox") You could also use;
if( c is System.Windows.Forms.TextBox )
this lets the value change for controls derived from TextBox too :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972