Adding dynamically new lines and columns to a grid ?
-
Hi, Does anybody know if it is possible to add dynamically new lines or columns to a grid at runtime ? Thanks, Fred
-
Hi, Does anybody know if it is possible to add dynamically new lines or columns to a grid at runtime ? Thanks, Fred
You have to use code (c#) not XAML to do this. Something along the lines of: myGrid.ColumnDefinitions.Add(new ColumnDefintion);
-
You have to use code (c#) not XAML to do this. Something along the lines of: myGrid.ColumnDefinitions.Add(new ColumnDefintion);
Thanks. But how do you do to access to the Grid.Row field in C# ? RowDefinition ligne_def = new RowDefinition(); ligne_def.Height = new GridLength(50); Grille.RowDefinitions.Add(ligne_def); Grille.RowDefinitions.Add(ligne_def); Button bouton_new = new Button(); bouton_new.Content = "nouveau bouton"; // And how to access to the fields Grid.Row="" and Grid.Column="" ? Grille.Children.Add(bouton_new); For example :
-
Thanks. But how do you do to access to the Grid.Row field in C# ? RowDefinition ligne_def = new RowDefinition(); ligne_def.Height = new GridLength(50); Grille.RowDefinitions.Add(ligne_def); Grille.RowDefinitions.Add(ligne_def); Button bouton_new = new Button(); bouton_new.Content = "nouveau bouton"; // And how to access to the fields Grid.Row="" and Grid.Column="" ? Grille.Children.Add(bouton_new); For example :
WolveFred2 wrote:
how do you do to access to the Grid.Row field in C# ?
Grid.SetRow(bouton_new, rowvalue);
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Thursday, January 29, 2009 1:52 PM
-
WolveFred2 wrote:
how do you do to access to the Grid.Row field in C# ?
Grid.SetRow(bouton_new, rowvalue);
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Thursday, January 29, 2009 1:52 PM
There is no SetRow() method on my Grid object. I'm using Silverlight 2.0, without other plugins. There is a SetValue() method (SetValue(DependencyProperty dp, object value)). It deals about System.Windows.DependencyObject. Would it be useful for my problem ?
-
There is no SetRow() method on my Grid object. I'm using Silverlight 2.0, without other plugins. There is a SetValue() method (SetValue(DependencyProperty dp, object value)). It deals about System.Windows.DependencyObject. Would it be useful for my problem ?
Oops....sorry :)
Grid.SetRow(bouton_new, rowvalue);
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Oops....sorry :)
Grid.SetRow(bouton_new, rowvalue);
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks ;) 1) But if there is more than one Grid on the application, how to set which Grid ? 2) Second question, is it possible to insert a row ? 3) Is it possible to merge cells, like in HTML Tables ?
-
Thanks ;) 1) But if there is more than one Grid on the application, how to set which Grid ? 2) Second question, is it possible to insert a row ? 3) Is it possible to merge cells, like in HTML Tables ?
WolveFred2 wrote:
- But if there is more than one Grid on the application, how to set which Grid ?
Which grid the property applies to is based on the element you pass to SetRow() - the element's "parent" grid.
WolveFred2 wrote:
- Second question, is it possible to insert a row ?
It should be the same as inserting a column as Colin showed in his reply.
WolveFred2 wrote:
- Is it possible to merge cells, like in HTML Tables ?
I don't know what you mean since I don't know HTML :) An element can span multiple rows and/or columns of a grid. You'd use the SetRowSpan()/SetColumnSpan() methods to adjust that from code (the default is 1). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
WolveFred2 wrote:
- But if there is more than one Grid on the application, how to set which Grid ?
Which grid the property applies to is based on the element you pass to SetRow() - the element's "parent" grid.
WolveFred2 wrote:
- Second question, is it possible to insert a row ?
It should be the same as inserting a column as Colin showed in his reply.
WolveFred2 wrote:
- Is it possible to merge cells, like in HTML Tables ?
I don't know what you mean since I don't know HTML :) An element can span multiple rows and/or columns of a grid. You'd use the SetRowSpan()/SetColumnSpan() methods to adjust that from code (the default is 1). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thank you a lot for your help, it's really more clear than before. There is just again a misunderstood point : >> Is it possible to insert a row ? > It should be the same as inserting a column as Colin showed in his reply. > myGrid.ColumnDefinitions.Add(new ColumnDefintion); myGrid.ColumnDefinitions.Insert(1, col_def); That is inserting a column definition amongs others, but do not move the following columns. It seems that columns are statically positionned, as there have a property like Grid.Column="2". So is it really possible to insert columns and rows ? I wish I am wrong !
modified on Monday, February 2, 2009 10:56 AM
-
Thank you a lot for your help, it's really more clear than before. There is just again a misunderstood point : >> Is it possible to insert a row ? > It should be the same as inserting a column as Colin showed in his reply. > myGrid.ColumnDefinitions.Add(new ColumnDefintion); myGrid.ColumnDefinitions.Insert(1, col_def); That is inserting a column definition amongs others, but do not move the following columns. It seems that columns are statically positionned, as there have a property like Grid.Column="2". So is it really possible to insert columns and rows ? I wish I am wrong !
modified on Monday, February 2, 2009 10:56 AM
WolveFred2 wrote:
It seems that columns are statically positionned, as there have a property like Grid.Column="2".
It's up to you to place the row/column definitions where you want them. If you insert a column/row dynamically then you may need to adjust the properties of the child elements so they shift to the new column/row positions. This can all be done programatically. What are you trying to do that's not working? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
WolveFred2 wrote:
It seems that columns are statically positionned, as there have a property like Grid.Column="2".
It's up to you to place the row/column definitions where you want them. If you insert a column/row dynamically then you may need to adjust the properties of the child elements so they shift to the new column/row positions. This can all be done programatically. What are you trying to do that's not working? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Okay, I agree I could do it myself. I was just surprised it wasn't already in place. But I found a component that does it : http://www.vectorlight.net/controls/table.aspx It's an extension to the Grid component. It's nearly usable except a little bug.