Removing Last Row in WPF Grid
I want to remove the last row of a grid. I expect the last line to remove
the row with the '2' in it. But whether i removeAt row 0 or 1, the 0th row
is always removed. I suspect I am missing something subtle about rows vs
grids. What am I doing wrong:
// Create row 0
RowDefinition row = new RowDefinition();
row.Height = GridLength.Auto;
myGrid.RowDefinitions.Add(row);
// Add someting to it
TextBox tb = new TextBox();
tb.Text = "1";
Grid.SetColumn(tb, 0);
Grid.SetRow(tb, 0);
myGrid.Children.Add(tb);
// create row 1
row = new RowDefinition();
row.Height = GridLength.Auto;
myGrid.RowDefinitions.Add(row);
// Add something to it
tb = new TextBox();
tb.Text = "2";
Grid.SetColumn(tb, 0);
Grid.SetRow(tb, 1);
myGrid.Children.Add(tb);
// Delete row 1 (second row 0-indexed) <<< only row 0 is deleted
myGrid.RowDefinitions.RemoveAt(1);
Note: I also tried:
myGrid.RowDefinitions.Remove(myGrid.RowDefinitions[1]);
same result. Thanks for any insight.
No comments:
Post a Comment