Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#WinForm
I have some textboxes in a panel on a form. Is it possible to do a double.Parse(txt.Text) for just these textboxes in the panel through a foreach?
Posted 27-Sep-12 22:01pm
Frans Jan1.9K
Edited 27-Sep-12 22:04pm
v2
Comments
Kenneth Haugland at 28-Sep-12 4:03am
   
Pleas tag the question properly, WPF or WinForms or?
Frans Jan at 28-Sep-12 4:04am
   
Sorry, forgot to add that tag
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this code:
foreach (Control ctrl in panel1.Controls)
{
   if (ctrl is TextBox)
   {
      double dbl = Double.Parse(((TextBox)ctrl).Text);
   }
}
  Permalink  
Comments
Espen Harlinn at 29-Sep-12 6:56am
   
5'ed!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Two Simple Approaches to WinForms Dirty Tracking[^] discusses an approach where you can loop through controls.
 
Check if these controls are textboxes and then parse the values for these controls.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 576
1 OriginalGriff 183
2 Tadit Dash 150
3 Peter Leow 140
4 Sergey Alexandrovich Kryukov 121
0 Sergey Alexandrovich Kryukov 9,280
1 OriginalGriff 5,473
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid