Click here to Skip to main content
12,999,010 members (47,891 online)
Rate this:
Please Sign up or sign in to vote.
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:


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 1:53am
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.
Rate this: bad
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
Rate this: bad
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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 29 May 2013
Copyright © CodeProject, 1999-2017
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