I have this situation 1000 times already: I have grid with 2 columns and many rows. Mostly i have TextBlock in first column and TextBox in second but not always. Now when I have 50 rows and I decide to move row 49 to the first row in grid, and I don't want to swap rows, I want to insert it to first place. Then I need to change values of Grid.Row and Grid.Column of all the rest of controls. This i driving me crazy. How can I make this easier?
Asked
Active
Viewed 2,594 times
3 Answers
0
If you have formatted your xaml code well, you can hold Alt key to select and cut Grid.Row="x" in every line and hold Alt key to select and paste them one line down.
eg.
<TextBlock Grid.Row="0" Text="a"/>
<TextBlock Grid.Row="1" Text="b"/>
<TextBlock Grid.Row="2" Text="c"/>
<TextBlock Grid.Row="3" Text="d"/>
you want to move <TextBlock Grid.Row="3" Text="d"/>
to the top. Just hold "Alt" key to select and copy:
Grid.Row="1"
Grid.Row="2"
Grid.Row="3"
Use Alt key again to paste them to replace the original
Grid.Row="0"
Grid.Row="1"
Grid.Row="2"
so you well get
<TextBlock Grid.Row="1" Text="a"/>
<TextBlock Grid.Row="2" Text="b"/>
<TextBlock Grid.Row="3" Text="c"/>
<TextBlock Grid.Row="3" Text="e"/>
Then just move <TextBlock Grid.Row="3" Text="d"/>
to the top and change it Grid.Row
to 0

Bolu
- 8,696
- 4
- 38
- 70
-
A bit too dependent on formatting, also depends on how you sort things, e.g. by row or by column. – H.B. Aug 15 '11 at 12:46
-
@H.B. agree, if as OP said `I have this situation 1000 times already` I think it is the time to adapt an easy to modified formatting. – Bolu Aug 15 '11 at 12:50
0
You could use something like the markup extension i outlined in this question right from the beginning, if you then need to insert a new row that should be less trouble.
0
-
Actually it should probably be an `ItemsControl`, as there is apparently no need for selection. – H.B. Aug 15 '11 at 12:47
-
@H.B. Yes you're right but I'm struggling to find a simple example to link. – Phil Gan Aug 15 '11 at 12:53