[Visual Basic, C#] 注意 此示例显示如何使用 Item 属性(DataGrid 索引器)的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
[Visual Basic]
Private Sub PrintCells(ByVal myGrid As DataGrid)
Dim iRow As Integer
Dim iCol As Integer
Dim myTable As DataTable
' Assumes the DataGrid is bound to a DataTable.
myTable = CType(DataGrid1.DataSource, DataTable)
For iRow = 0 To myTable.Rows.Count - 1
For iCol = 0 To myTable.Columns.Count - 1
Console.WriteLine(myGrid(iRow, iCol))
Next iCol
Next iRow
End Sub
[C#]
private void PrintCellValues(DataGrid myGrid){
int iRow;
int iCol;
DataTable myTable;
// Assumes the DataGrid is bound to a DataTable.
myTable = (DataTable) dataGrid1.DataSource;
for(iRow = 0;iRow < myTable.Rows.Count ;iRow++) {
for(iCol = 0;iCol < myTable.Columns.Count ;iCol++) {
Console.WriteLine(myGrid[iRow, iCol]);
}
}
}
---------------------------------------------------------------------
MSDN上复制过来的