Click here to Skip to main content
15,895,370 members
Home / Discussions / C#
   

C#

 
GeneralRe: Parsing a string object Pin
Jeff Varszegi26-Apr-04 18:05
professionalJeff Varszegi26-Apr-04 18:05 
GeneralRe: Parsing a string object Pin
Tony D. Abel27-Apr-04 7:02
Tony D. Abel27-Apr-04 7:02 
GeneralFormula Pin
DucLinh26-Apr-04 15:56
DucLinh26-Apr-04 15:56 
Generalcreating an array of existing WinForm controls Pin
Roman Nurik26-Apr-04 13:48
Roman Nurik26-Apr-04 13:48 
GeneralRe: creating an array of existing WinForm controls Pin
Roman Nurik26-Apr-04 13:51
Roman Nurik26-Apr-04 13:51 
GeneralRe: creating an array of existing WinForm controls Pin
Mike Dimmick26-Apr-04 23:43
Mike Dimmick26-Apr-04 23:43 
GeneralRe: creating an array of existing WinForm controls Pin
Mike Ellison26-Apr-04 17:03
Mike Ellison26-Apr-04 17:03 
GeneralRe: creating an array of existing WinForm controls Pin
Heath Stewart27-Apr-04 4:17
protectorHeath Stewart27-Apr-04 4:17 
You can either enumerate (or iterate) over the Controls collection property which already contains your controls that are displayed on a form, or add specific control references (as Mike mentioned, not "pointers").

If you only want to deal with controls of a specific type, for instance, then you could do something like this:
foreach (Control c in Controls)
{
  if (c is Button)
  {
    Button b = (Button)c;
    b.Text = "Click me!";
  }
}
When you enumerate a collection, list, or any other IEnumerable implementation, do not change the underlying enumerable otherwise an exception will be thrown. If you must change the collection or list or whatever, then iterate (the ol' for loop) over the collection or list instead and update your current index accordingly.

There have been times when I wanted to keep a separate list or array (which is a static list, BTW) of certain controls in my form so I could deal with them in a loop as well. You could easily do something like this:
Control[] controls = new Control[] {
  this.textBox1,
  this.textBox2,
  thix.button5
};
// Later...
foreach (Control c in controls)
  // ...
// -- OR --
for (int i=0; i<controls.Length; i++)
  // ...


 

Microsoft MVP, Visual C#
My Articles
GeneralLabel question... Pin
spoon vs fork26-Apr-04 13:47
spoon vs fork26-Apr-04 13:47 
GeneralRe: Label question... Pin
Roman Rodov26-Apr-04 14:55
Roman Rodov26-Apr-04 14:55 
GeneralRe: Label question... Pin
Jay Shankar26-Apr-04 15:43
Jay Shankar26-Apr-04 15:43 
GeneralListView and Inserting Subitems Pin
valikac26-Apr-04 12:17
valikac26-Apr-04 12:17 
GeneralRe: ListView and Inserting Subitems Pin
Jon G26-Apr-04 12:59
Jon G26-Apr-04 12:59 
GeneralRe: ListView and Inserting Subitems Pin
valikac26-Apr-04 14:40
valikac26-Apr-04 14:40 
GeneralRe: ListView and Inserting Subitems Pin
osto26-Apr-04 17:17
osto26-Apr-04 17:17 
GeneralRe: ListView and Inserting Subitems Pin
valikac26-Apr-04 18:10
valikac26-Apr-04 18:10 
GeneralUsing Bitmap and got exception in dispose Pin
kobyb26-Apr-04 11:28
kobyb26-Apr-04 11:28 
Generalconditional operator (?:) performance Pin
Anonymous26-Apr-04 10:53
Anonymous26-Apr-04 10:53 
GeneralRe: conditional operator (?:) performance Pin
Daniel Turini26-Apr-04 11:21
Daniel Turini26-Apr-04 11:21 
GeneralRe: conditional operator (?:) performance Pin
Mike Dimmick26-Apr-04 23:53
Mike Dimmick26-Apr-04 23:53 
GeneralRe: conditional operator (?:) performance Pin
Anonymous27-Apr-04 2:49
Anonymous27-Apr-04 2:49 
GeneralDataGrid row: RowState unchange problem Pin
Chris#26-Apr-04 10:47
Chris#26-Apr-04 10:47 
GeneralRe: DataGrid row: RowState unchange problem Pin
Heath Stewart26-Apr-04 11:50
protectorHeath Stewart26-Apr-04 11:50 
GeneralRe: DataGrid row: RowState unchange problem Pin
Chris#27-Apr-04 4:49
Chris#27-Apr-04 4:49 
GeneralGarbage collector Pin
Ruchi Gupta26-Apr-04 10:39
Ruchi Gupta26-Apr-04 10:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.