我有一个数据网格如下;
mainWindow.xaml:
<DataGrid Name="CSVDataGrid" ItemsSource="{Binding}" AutoGenerateColumns="False" Margin="20,5,0,0" HorizontalAlignment="Left"
Grid.ColumnSpan="4" Grid.Row="3" Grid.Column="0" SelectionChanged="CSVDataGrid_SelectionChanged" Width="560">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Project}" Header="Project" Width="50" />
<DataGridTextColumn Binding="{Binding Description}" Header="Description" Width="200"/>
</DataGrid.Columns>
</DataGrid>
MainWindow.xaml.cs
private void SubmitBtn_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < CSVDataGrid.Items.Count; i++)
{
DataGridRow row = (DataGridRow) CSVDataGrid.ItemContainerGenerator.ContainerFromIndex(i);
if (row != null)
{
object[] itemArray = ((System.Data.DataRowView) (row.Item)).Row.ItemArray;
MessageBox.Show(String.Format("Row = {0},{1},{3}",
itemArray[0].ToString(),
itemArray[1].ToString(),
i));
}
}
}
当用户点击按钮时,我想检索每一行的数据。目前,这仅适用于可见行。我怎样才能获得所有数据?