internal static IDataObject CreateDataObject( DataGridControl dataGridControl )
    {
      if( dataGridControl == null )
        throw new ArgumentNullException( "dataGridControl" );

      DataGridContext dataGridContext = DataGridControl.GetDataGridContext( dataGridControl );

      if( dataGridContext == null )
        return null;

      XceedDataObject dataObject = null;
      bool containsData = false;

      try
      {
        dataGridControl.ShowWaitCursor();

        Dictionary<string, ClipboardExporterBase> exporters = dataGridControl.ClipboardExporters;

        foreach( KeyValuePair<string, ClipboardExporterBase> keyPair in exporters )
        {
          if( keyPair.Value == null )
            throw new DataGridException( "ClipboardExporterBase cannot be null." );

          keyPair.Value.StartExporter( keyPair.Key );
        }

        using( ManualExporter exporter = new ManualExporter( exporters.Values as IEnumerable<ClipboardExporterBase> ) )
        {
          exporter.Export( dataGridContext );
        }

        foreach( KeyValuePair<string, ClipboardExporterBase> keyPair in exporters )
        {
          keyPair.Value.EndExporter( keyPair.Key );

          if( dataObject == null )
          {
            dataObject = new XceedDataObject();
          }

          object clipboardExporterValue = keyPair.Value.ClipboardData;

          // For other formats, we directly copy the content to the IDataObject
          if( clipboardExporterValue != null )
          {
            ( ( IDataObject )dataObject ).SetData( keyPair.Key, clipboardExporterValue );
            containsData = true;
          }

          keyPair.Value.ResetExporter();
        }
      }
      finally
      {
        dataGridControl.HideWaitCursor();
      }

      // Only return dataObject some data was copied
      if( containsData )
        return dataObject as IDataObject;

      return null;
    }
Пример #2
0
        internal static IDataObject CreateDataObject(DataGridControl dataGridControl)
        {
            if (dataGridControl == null)
            {
                throw new ArgumentNullException("dataGridControl");
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(dataGridControl);

            if (dataGridContext == null)
            {
                return(null);
            }

            XceedDataObject dataObject   = null;
            bool            containsData = false;

            try
            {
                dataGridControl.ShowWaitCursor();

                Dictionary <string, ClipboardExporterBase> exporters = dataGridControl.ClipboardExporters;

                foreach (KeyValuePair <string, ClipboardExporterBase> keyPair in exporters)
                {
                    if (keyPair.Value == null)
                    {
                        throw new DataGridException("ClipboardExporterBase cannot be null.");
                    }

                    keyPair.Value.StartExporter(keyPair.Key);
                }

                using (ManualExporter exporter = new ManualExporter(exporters.Values as IEnumerable <ClipboardExporterBase>))
                {
                    exporter.Export(dataGridContext);
                }

                foreach (KeyValuePair <string, ClipboardExporterBase> keyPair in exporters)
                {
                    keyPair.Value.EndExporter(keyPair.Key);

                    if (dataObject == null)
                    {
                        dataObject = new XceedDataObject();
                    }

                    object clipboardExporterValue = keyPair.Value.ClipboardData;

                    // For other formats, we directly copy the content to the IDataObject
                    if (clipboardExporterValue != null)
                    {
                        (( IDataObject )dataObject).SetData(keyPair.Key, clipboardExporterValue);
                        containsData = true;
                    }

                    keyPair.Value.ResetExporter();
                }
            }
            finally
            {
                dataGridControl.HideWaitCursor();
            }

            // Only return dataObject some data was copied
            if (containsData)
            {
                return(dataObject as IDataObject);
            }

            return(null);
        }