Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Adding dynamically new lines and columns to a grid ?

Adding dynamically new lines and columns to a grid ?

Scheduled Pinned Locked Moved WPF
cssquestion
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WolveFred2
    wrote on last edited by
    #1

    Hi, Does anybody know if it is possible to add dynamically new lines or columns to a grid at runtime ? Thanks, Fred

    C 1 Reply Last reply
    0
    • W WolveFred2

      Hi, Does anybody know if it is possible to add dynamically new lines or columns to a grid at runtime ? Thanks, Fred

      C Offline
      C Offline
      ColinM123
      wrote on last edited by
      #2

      You have to use code (c#) not XAML to do this. Something along the lines of: myGrid.ColumnDefinitions.Add(new ColumnDefintion);

      Online Guitar Tools

      W 1 Reply Last reply
      0
      • C ColinM123

        You have to use code (c#) not XAML to do this. Something along the lines of: myGrid.ColumnDefinitions.Add(new ColumnDefintion);

        Online Guitar Tools

        W Offline
        W Offline
        WolveFred2
        wrote on last edited by
        #3

        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 :

        M 1 Reply Last reply
        0
        • W WolveFred2

          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 :

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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

          W 1 Reply Last reply
          0
          • M Mark Salsbery

            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

            W Offline
            W Offline
            WolveFred2
            wrote on last edited by
            #5

            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 ?

            M 1 Reply Last reply
            0
            • W WolveFred2

              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 ?

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Oops....sorry :)

              Grid.SetRow(bouton_new, rowvalue);

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              W 1 Reply Last reply
              0
              • M Mark Salsbery

                Oops....sorry :)

                Grid.SetRow(bouton_new, rowvalue);

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                W Offline
                W Offline
                WolveFred2
                wrote on last edited by
                #7

                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 ?

                M 1 Reply Last reply
                0
                • W WolveFred2

                  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 ?

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  WolveFred2 wrote:

                  1. 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:

                  1. 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:

                  1. 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:

                  W 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    WolveFred2 wrote:

                    1. 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:

                    1. 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:

                    1. 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:

                    W Offline
                    W Offline
                    WolveFred2
                    wrote on last edited by
                    #9

                    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

                    M 1 Reply Last reply
                    0
                    • W WolveFred2

                      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

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      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:

                      W 1 Reply Last reply
                      0
                      • M Mark Salsbery

                        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:

                        W Offline
                        W Offline
                        WolveFred2
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups