2012-04-10 31 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