我正在尝试将DataTable分配为dataGrid1的项源dataGrid1.ItemsSource = dtselect.DefaultView,但它给出了System.OutOfMemoryException
我有一个包含多个DataTable的数据集。我在该按钮单击上随机创建了一个按钮,我想显示从DataTable到dataGrid1的数据,但是这里的问题是DataTable有超过200万行,当我单击按钮时,它将花费2gb以上的内存并给我System。 OutOfMemoryException。
formatNumber = (num)=>{
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
var formattedNumber = formatNumber(10000000);
console.log(formattedNumber);
我希望输出的内存使用量和显示结果更少,而不是System.OutOfMemoryException
答案 0 :(得分:0)
<Viewbox Grid.Row="3" Stretch="Fill">
<DataGrid x:Name="dataGrid1" Grid.Row="3" VirtualizingPanel.VirtualizationMode="Recycling" BorderThickness="0" VirtualizingPanel.IsVirtualizing="True" CanUserSortColumns="True" EnableRowVirtualization="True" IsReadOnly="True" CanUserResizeColumns="True" CanUserAddRows="False" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" Height="600" Width="auto" ItemsSource="{Binding}" AutoGenerateColumns="False" ScrollViewer.VerticalScrollBarVisibility="Auto" Background="#b5d2fc" ClipboardCopyMode="IncludeHeader" SelectionMode="Extended" CanUserDeleteRows="False">
<DataGrid.Columns>
<DataGridTextColumn Width="200" Header="Day" Binding="{Binding Day}"/>
<DataGridTextColumn Width="200" Header="Date" Binding="{Binding Date}"/>
<DataGridTextColumn Width="200" Header="Time" Binding="{Binding Time}"/>
<DataGridTextColumn Width="200" Header="Lat" Binding="{Binding Lat}"/>
<DataGridTextColumn Width="200" Header="Long" Binding="{Binding Long}"/>
<DataGridTextColumn Width="400" Header="Address" Binding="{Binding Address}"/>
<DataGridTextColumn Width="200" Header="Accuracy" Binding="{Binding Accuracy}"/>
<DataGridTextColumn Width="200" Header="Type" Binding="{Binding Type}"/>
</DataGrid.Columns>
</DataGrid>
</Viewbox>
我只是添加了Viewbox,如果我加载了两个以上具有大量数据的文件,那么我的代码也可以正常工作,而且占用的内存更少