Ask a questionAsk a question
 

AnswerRuntime allot the rows and columns in Grid

  • Friday, November 06, 2009 3:22 PMRammohan Ammiti Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello

     

     

    <ScrollViewer Grid.ColumnSpan="4" Grid.Row="1" VerticalScrollBarVisibility="Auto" Margin="1,7,0,0" >

     

     

    <StackPanel x:Name="TopStackPanel" Grid.Column="0" Grid.ColumnSpan="5" Grid.Row="1" Margin="0,0,0,4" AllowDrop="True" />

     

     

    </ScrollViewer>

    right now i alloted the rows and columns at runtime the above way. but i need that should be allowted  at runtime.


    pls suggest me

    Thanks
    Ram.

Answers

  • Monday, November 09, 2009 6:06 PMReed Copsey, Jr. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    If I understand you completely -

    Setup your form using the designer, and set the appropriate rows/columns for your controls.


    Basically, when you click the button, you can have an event handler attached to the button (on button's Click event).  The event handler could go through each of your "controls", and change their columns.

    Just call, for each control:

        Grid.SetColumn(theControl, System.Math.Max(0, Grid.GetColumn(theControl) - 1)); // Move "theControl" one space left in the grid, but not past column 0


    That will "move" the control. 
    Reed Copsey, Jr. - http://reedcopsey.com

All Replies

  • Friday, November 06, 2009 5:41 PMReed Copsey, Jr. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    If I understand you correctly, you're trying to set the Grid.Column="0" Grid.ColumnSpan="5" Grid.Row="1" in code instead of xaml?

    If so, you need to use the methods on the Grid class itself.  These properties are Attached Properties, they are part of the Grid class, but can be "attached" to any UIElement.

    For example, if you're doing it in the codebehind, you could write:

    Grid.SetColumn(this.TopStackPanel, 0);
    Grid.SetRow(this.TopStackPanel, 1);
    Grid.SetColumnSpan(this.TopStackPanel, 5);
    
    If you want details, you can read up on Grid.SetRow and the other related Attached Properties.

    Reed Copsey, Jr. - http://reedcopsey.com
  • Saturday, November 07, 2009 7:31 AMRammohan Ammiti Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Reed thanks for your kind reply..

    1. questin: page load time i need static one only. if i click any button that should changed the columns and rows according to my positions.
     but our  code default Grid.setcolumns and setrows methods through working right?


    2. if first one is not right way...

    how i remove the space the of the first control  and second one move to first positions.. suggest me very urgent





  • Monday, November 09, 2009 6:06 PMReed Copsey, Jr. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    If I understand you completely -

    Setup your form using the designer, and set the appropriate rows/columns for your controls.


    Basically, when you click the button, you can have an event handler attached to the button (on button's Click event).  The event handler could go through each of your "controls", and change their columns.

    Just call, for each control:

        Grid.SetColumn(theControl, System.Math.Max(0, Grid.GetColumn(theControl) - 1)); // Move "theControl" one space left in the grid, but not past column 0


    That will "move" the control. 
    Reed Copsey, Jr. - http://reedcopsey.com