Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 20th, 2007, 07:27 AM
Registered User
 
Join Date: Jul 2007
Location: Overpelt, , Belgium.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read input from Dynamically Controls

Hello,

I have created some input maskedTextBoxes dynamically with the code below.

But now I have to calculated the sum from these input's.
But I don't now how to read these values out of these dynamically created controls?

All info is welcome,




public byte aantalMeetingen;

private void button1_Click_1(object sender, EventArgs e)
{
     flowLayoutPanel1.Controls.Clear();

     aantalMeetingen = Convert.ToByte(mskAantalMeetingen.Text );
      if (aantalMeetingen <= 15)
      {
          for (byte i = 0; i < aantalMeetingen; i++)
          {
               Label newLabel = new Label();
               newLabel.Name = "lblInput" + Convert.ToString(i);
               newLabel.Text = "Input " + Convert.ToString(i + 1) + " : ";
               newLabel.Width = 55;
               newLabel.Left = 5;
               newLabel.Top = i * 12;

               flowLayoutPanel1.Controls.Add(newLabel);

               MaskedTextBox newMask = new MaskedTextBox();
               newMask.Name = "mskInput" + Convert.ToString(i);
               newMask.Mask = "00000";
               newMask.Left = newLabel.Left + newLabel.Width + 5;
               newMask.Top = newLabel.Top;
               newMask.Width = 40;
               flowLayoutPanel1.Controls.Add(newMask);

               flowLayoutPanel1.FlowDirection = FlowDirection.LeftToRight;


            }
         }

    }


Thanks,

Francois
Reply With Quote
  #2 (permalink)  
Old July 21st, 2007, 12:39 AM
Authorized User
 
Join Date: Sep 2004
Location: Edegem, Antwerpen, Belgium.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the easiest way is to loop over the Controls from the flowLayoutPanel1 and then check the name of the control.

Something like this:
foreach (Control control in flowLayoutPanel1.Controls)
{
    if (control is MaskedTextBox)
    {
        MaskedTextBox mskInput = (MaskedTextBox)control;
        MessageBox.Show(string.Format("Name: {0} - Value: {1}", mskInput.Name, mskInput.Text));
    }
}

Greetz,

Geert

http://geertverhoeven.blogspot.com
Reply With Quote
  #3 (permalink)  
Old July 25th, 2007, 12:58 PM
Registered User
 
Join Date: Jul 2007
Location: Overpelt, , Belgium.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Bedankt Geert.

Thanks,

Francois
Reply With Quote
  #4 (permalink)  
Old August 20th, 2007, 06:56 PM
Registered User
 
Join Date: Aug 2007
Location: Bellingham, WA, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you overrode the CreateChildControls() method and know the naming convention of the controls you can access this way (granted you added to a placeholder).
Code:
for (byte i = 0; i < aantalMeetingen; i++)
{
    MaskedTextBox newMask = flowLayoutPanel.FindControl(string.Format("mskInput{0}", Convert.ToString(i)));

    if (newMask != null)
    {
        // do stuff here;
    }
}

http://www.willasrari.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Controls Dynamically andyj00 C# 0 March 19th, 2007 08:54 AM
how to read node dynamically gantait XSLT 4 February 27th, 2007 11:01 AM
Creating controls dynamically Renu ASP.NET 1.0 and 1.1 Basics 9 December 19th, 2004 10:21 AM
Dynamically Add input tags Jstmehr4u3 Javascript How-To 2 July 29th, 2003 04:03 AM



All times are GMT -4. The time now is 09:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.