Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF grid row
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 15-May-13 2:53am
Comments
Leslieytx at 15-May-13 7:53am
   
Also I delete the child in this Row
Irina Pykhova at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Every time you remove a rowdefinition, you need to delete every control in this row and redefine the whole rowdefiniton.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Leslieytx at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 150
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 29 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100