Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my code

   private void button1_Click(object sender, RoutedEventArgs e)
       {
           DateTime dt1 = Convert.ToDateTime(label1.Content + "/" + label2.Content + "/" + label5.Content);
           DateTime dt2 = Convert.ToDateTime(label3.Content + "/" + label4.Content + "/" + label6.Content);
           TimeSpan ts =  dt2-dt1 ;
           int days = ts.Days;
           label14.Content = ts.Days;
           for (int i = 0; i < 50; i++)
           {
               TextBlock TXB = new TextBlock();
               TXB.Background = new LinearGradientBrush(Colors.Red, Colors.LightCyan, new Point(0, 0), new Point(1, 1));
               TXB.Text =  i.ToString();
               TXB.HorizontalAlignment = HorizontalAlignment.Left; TXB.VerticalAlignment = VerticalAlignment.Stretch;
               TXB.Width = 30;
               TXB.Name = "T" + i.ToString();
               if (TXB.Margin == TXB.Margin)
               {
                   TXB.Margin = new Thickness(TXB.Margin.Left,  0, TXB.Margin.Right + 20, 0);

               }
this.grid2.Children.Add(TXB);

           }


Now this is what i am trying to do, im trying to make it so when i click this button a row of textbolocks will come up in grid1, for example

i = textblock
textblock number = 6
i location.right = +1

so then its in like a row like
iiiiii etc etc...
and there are 6 i's in a row
Posted

You can do what you are doing, but the Grid you are inserting the TextBlocks into needs to have ColumnDefinitions for each TextBlock otherwise they will all be in the same Grid cell.

You can define the 6 columns for the grid and then set the Grid.Column attached properrty for each TextBlock so it goes in the correct column.

Why not use a StackPanel with Orientation=Horizontal instead of a Grid? Then the system will lay them out for you as you insert them.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 5-Jun-11 16:07pm    
Right, a 5.
--SA
I think you just want to set the left and top properties of the controls you're creating, to put them where you want. Is that right ?
 
Share this answer
 
Comments
[no name] 9-Jun-11 23:10pm    
yes

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