Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i add an array of text box into grid in row and column :
C#
  public void AddTable(int row,int col)
        {
            int i, k;
            int basex = 15;
            int basey = 15;
            int count = 0;
        GroupBox group = new GroupBox();  // for managing txtTable 
        Grid grid2 = new Grid();
            for (i = 0; i < 100; i++)
            {
                txtTable[i] = new TextBox();
                txtTable[i].Visibility = Visibility.Hidden;
            }
            for (i = 0; i < row; i++)
            {
                for (k = 0; k < col; k++)
                {
                    txtTable[count].Margin = new Thickness(basex, basey,0,0);
                    txtTable[count].Visibility = Visibility.Visible ;
                    txtTable[count].Text = "";
                    grid2.Children.Add ( txtTable[count]);
                    
                    count++;
                    basex += 25;
                }
                basex = 15;
                basey += 25;
            }
            group.Content = grid2;
            group.Visibility = Visibility.Visible;
            group.Header = "matris";
            group.VerticalAlignment = VerticalAlignment.Top;
            group.HorizontalAlignment = HorizontalAlignment.Right;
            grid2.Visibility = Visibility.Visible;
            grid1.Children.Add(group); // grid1 is main grid
           
          
}

i wrote this code but in the screen,size of text boxes are not equivalent
Posted
Updated 25-May-12 0:19am
v2
Comments
Jim Jos 25-May-12 7:54am    
You are setting only the margin? where you are settng the width?
Reza Oruji 25-May-12 8:06am    
i used width and height :
txtTable[i].Width = 20;
txtTable[i].Height = 25;
in loop but had no effect

1 solution

Hi,

TextBox txt = new Textbox();
GrdDynamic.Rows[0].Cells[0].Controls.Add(txt);


I hope it works for u.
 
Share this answer
 
Comments
Reza Oruji 26-May-12 10:41am    
thanks,but it doesn't work.
can you debug my code please?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900