Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2007, 07:27 AM
Registered User
 
Join Date: Jul 2007
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
 
Old July 21st, 2007, 12:39 AM
Authorized User
 
Join Date: Sep 2004
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
 
Old July 25th, 2007, 12:58 PM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Bedankt Geert.

Thanks,

Francois
 
Old August 20th, 2007, 06:56 PM
Registered User
 
Join Date: Aug 2007
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.