Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2385
outofmemory when copy data
posted

I create a grid which has only one column with about 800K rows.

When I copy all the data, it launch a out of memory exception.

Parents
  • 54937
    Offline posted

    The grid writes to the clipboard in multiple formats including CSV, Text, Html and its own internal format. In this case the Html format results in a string of approximalely 123,000,000 characters and .net cannot generate a string of that length because it doesn't have a large enough contiguous block of memory. I would probably recommend not letting the user try to copy all the data to the clipboard (e.g. handle the ExecutingCommand and setting e.Cancel to true if there are selected fields) if you have such a large data source.

      private void grid_ExecutingCommand(object sender, Infragistics.Windows.Controls.Events.ExecutingCommandEventArgs e)
      {
       if (e.Command == DataPresenterCommands.Copy ||
        e.Command == DataPresenterCommands.Cut)
       {
        DataPresenterBase dp = sender as DataPresenterBase;

        if (dp.SelectedItems.Fields.Count > 0)
        {
         e.Cancel = true;
         return;
        }
       }
      }

    If you must do this then perhaps you can exclude some formats (e.g. Html). Note it still may be possible to exceed the available memory. You can do this by handling the DataObject.SettingData attached event (e.g. <igDP:XamDataGrid x:Name="grid" DataObject.SettingData="grid_SettingData" ).

      private void grid_SettingData(object sender, DataObjectSettingDataEventArgs e)
      {
       if (e.Format == DataFormats.Html)
       {
        e.CancelCommand();
       }
      }

Reply Children