Skip to content

C# add Textbox to List

ilhami caliskan

ilhami caliskan

Asked Aug 9, 2013, 9:30 PM EDTSolved
Share
LinkedInX

 Hi All,
Anybody who can tell me why I cant add textbox to List?

         private List<String> inputList = new List<String>();


        public void AddInputBox(String data,String inputTxt)
        {            
            this.inputDataList.Add(data);

            
            TextBox txtBx = new TextBox();           
            txtBx.Height = 20;
            txtBx.Width = 50;
            txtBx.ReadOnly = true;


            int number = this.inputList.Count;
            txtBx.Location = new Point(number * 55, 20);
            txtBx.Text = inputTxt;

            //Add txtBox to inputList
            this.inputList.Add(txtBx); ----> here I get error "some invalide arguments"

            this.Controls.Add(txtBx);

Thanx to All

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    ✓ Accepted answer0
    Hi ilhami caliskan,

    Since you have a list of string type: List<string>, you cannot add a control to it. See, you're adding the TextBox itself instead of Text:

    this.inputList.Add(txtBx);

    You can do so:

    this.inputList.Add(txtBx.Text);


    Hope you got the point.

    Happy Coding :)
    0
  • ilhami caliskan
    0
    Thanx Sunny

    the code should be
    private List<TextBox> inputList = new List<TextBox>();

    sometimes we are just blind with open eyes... :P
    0
  • Sunny  Sharma
    0
    Well said. Please mark that as answer if it helped.
    0