.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
Runtime allot the rows and columns in Grid
Runtime allot the rows and columns in Grid
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
- 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- Marked As Answer byBruce.ZhouMSFT, ModeratorWednesday, November 11, 2009 12:21 PM
All Replies
- 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:
If you want details, you can read up on Grid.SetRow and the other related Attached Properties.Grid.SetColumn(this.TopStackPanel, 0); Grid.SetRow(this.TopStackPanel, 1); Grid.SetColumnSpan(this.TopStackPanel, 5);
Reed Copsey, Jr. - http://reedcopsey.com
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- 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- Marked As Answer byBruce.ZhouMSFT, ModeratorWednesday, November 11, 2009 12:21 PM


