Click here to Skip to main content
12,626,880 members (33,790 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 23:01pm
Frans Jan2.8K
Updated 27-Sep-12 23:04pm
v2
Comments
Kenneth Haugland 28-Sep-12 4:03am
   
Pleas tag the question properly, WPF or WinForms or?
Frans Jan 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100