Click here to Skip to main content
15,886,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a strange problem as follow:

seleted is a control in Grid;

the code like this:
int selectedColumnNumber = Grid.GetRow(selected);

but when I want to delete this Row using the code:

grid.RowDefinitions.RemoveAt(selectedColumnNumber);

it always delete the last row. I know when i delete a row I should redefinnition the RowDefinition,

the first time using this code, it still delete the last Row.

any help will be grateful!!
Posted
Comments
Leslieytx 15-May-13 7:53am    
Also I delete the child in this Row
Irina Pykhova 15-May-13 9:45am    
did you check, what value you get in Grid.GetRow? I.e. try something more simple, grid.RowDefinitions.RemoveAt(1) - does it work?
Leslieytx 15-May-13 11:38am    
Thanks for your reply
yes, I set a breakpoint to check the value Grid.GetRow, it is right number. but it delete a wrong row. the code grid.RowDefinitions.RemoveAt(1) delete the last row, even I set any other number in .RemoveAt(i),like .RemoveAt(0), it also delete the last number like number 4.

Every time you remove a rowdefinition, you need to delete every control in this row and redefine the whole rowdefiniton.
 
Share this answer
 
 
Share this answer
 
Comments
Leslieytx 15-May-13 11:18am    
Thank for your reply and I've checked these two article. But they ware different. what I mean is a Grid control in WPf not a DataGrid.
Leslieytx 15-May-13 11:34am    
Take instance:
here is a Grid, 3 Rows, 3 Columns. The row with row number 0, column number 1 cross two columns,(columnSpan = 2), the first column's rowSpan is 3. the third row also cross two columns(columnSpan =2), the second row has two column( (Grid.row = 1.,column =1),(row=1, column=2)).Now I want to delete the row with row number 0(cross two column), and the column with column number 0(cross three rows). when I delete row, it always delete a wrong row
every time remove a row , you should remove the rowdefinition and all children in this row. and then re-compute every row percent and redefine the whole rwodefinition, then add the other children
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900