I have a gridview and if I remove a row in this way:
foreach(Label l in currentRow) // I have an internal list of the labels
{
grdTable.Children.Remove(l); // the cells are filled with labels
}
grdTable.RowDefinitions.Remove(index);
it works if it is the last or second last row in other cases it fails.
an example where row 2. is deleted (index 1)
http://www.pic-upload.de/view-14074618/Unbenannt.png.html
row 3. is not shown and row 2. is really deleted, but it seems to me that row 3. is not correctly pushed on its right place. even updating the grid didn’t help.
edit: the current row is a List<Label> and I have a List<List<Label>> which represents the grid content. I already checked that the List<Label> which fills a row has always the same index as the RowDefinition which holds it.
any suggestions?
It looks to me as if you are using a
Gridcontrol, as opposed to a ‘GridView’ (I’m not aware of any WPF control with that name.) Your use ofRowDefinitionsis what suggests this to me.Within a
Grid, the row each control lies within is given by the value of itsGrid.Rowattached property. TheRowDefinitionsof the grid specify the heights of each row.When you delete a
RowDefinition, all you achieve is adjusting the heights of various rows within theGrid. Deleting aRowDefinitiondoes not affectGrid.Rowvalues of controls within the grid.To completely delete the row, you need to:
RowDefinition.Your code appears to be missing step 2.
Your approach works in the case where you delete the last row, because then there are no controls to shuffle up. It also appears to work in the case where you delete the second-last row. Suppose you have 10 rows, numbered from 0 to 9, and you delete row 8. There are now 9 row definitions, with numbers 0 to 8. However, the controls in the last row have their
Grid.Rowvalue still set to 9, which is now out of range. WPF puts all controls with theGrid.Rowout of range in the last row, so the controls in row 9 appear in row 8. If you add aRowDefinitionback to the grid, you’ll find that the controls in row 9 will then appear in the new row 9, leaving a gap in row 8.PS. Any reason you’re not using a
DataGrid?