2012-04-10 49 views

回答

6

對不起,這是在C#中,但原則上,你需要做的

int rows = theGrid.Rows; 
int columns = theGrid.Columns; 

int index = theGrid.Children.IndexOf(childElement); 

int row = index/columns; // divide 
int column = index%columns; // modulus 

而在VB .NET

dim rows as Integer = theGrid.Rows 
dim columns as Integer = theGrid.Columns 
dim index as Integer = theGrid.Children.IndexOf(childElement) 

dim row as integer = index \ columns 
dim column as integer = index mod columns 
+0

你是最棒的了! – 2012-04-10 17:02:43

+0

它似乎不像mod正在爲列工作。我嘗試了4個Mod 12,它應該返回4. – 2012-04-10 17:09:40

+0

4 mod 12是4. 12 mod 4 = 0,13 mod 4 = 1等 – Phil 2012-04-10 17:14:59