private void CopyGridContentToClipboard(DataGridViewClipboardCopyMode mode) { if (grd != null) { grd.ClipboardCopyMode = mode; DataObject dtObj = grd.GetClipboardContent(); if (dtObj == null) { return; } Clipboard.SetDataObject(dtObj); return; } }
private void copyData(DataGridViewClipboardCopyMode copymode) { try { var dgv = tabResults.SelectedTab.Controls[0] as DataGridView; dgv.ClipboardCopyMode = copymode; if (dgv != null && dgv.GetCellCount(DataGridViewElementStates.Selected) > 0) { Clipboard.SetDataObject(((DataGridView)tabResults.SelectedTab.Controls[0]).GetClipboardContent()); } } catch (System.Runtime.InteropServices.ExternalException) { AddMsg("The Clipboard could not be accessed. Please try again."); } }
public MyDataGridView() : base() { GoingToDialog = false; TakeCtrlTabKey = true; DoubleBuffered = true; AutoSave = true; DataError += MyDataGridView_DataError; BackgroundColor = SystemColors.Control; ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; myContextMenuStrip = new ContextMenuStrip(); myContextMenuStrip.Items.Add("Kopēt (Ctrl + C)", null, OnCopy); myContextMenuStrip.Items.Add("Kopēt bez virsrakstiem", null, OnCopyWithoutHeaders); ContextMenuStrip = myContextMenuStrip; SetMyToolTip(); ShowCellToolTips = false; }
private void ExportDataGridViewData(string filename, TextDataFormat format = TextDataFormat.CommaSeparatedValue) { IDataObject objectSave = Clipboard.GetDataObject(); bool multiSelectAllowed = dataGridViewLearningTasks.MultiSelect; DataGridViewClipboardCopyMode copyMode = dataGridViewLearningTasks.ClipboardCopyMode; dataGridViewLearningTasks.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridViewLearningTasks.MultiSelect = true; dataGridViewLearningTasks.SelectAll(); Clipboard.SetDataObject(dataGridViewLearningTasks.GetClipboardContent()); if (format == TextDataFormat.CommaSeparatedValue && Path.GetExtension(filename) != ".csv") { filename += ".csv"; } File.WriteAllText(filename, Clipboard.GetText(format)); dataGridViewLearningTasks.MultiSelect = multiSelectAllowed; dataGridViewLearningTasks.ClipboardCopyMode = copyMode; if (objectSave != null) { Clipboard.SetDataObject(objectSave); } }
#pragma warning restore 0414 #endif /// <include file='doc\DataGridView.uex' path='docs/doc[@for="DataGridView.DataGridView"]/*' /> /// <devdoc> /// <para>Initializes a new instance of the <see cref='System.Windows.Forms.DataGridView'/> class.</para> /// </devdoc> public DataGridView() { SetStyle(ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.UserMouse, true); SetStyle(ControlStyles.SupportsTransparentBackColor, false); // this class overrides GetPreferredSizeCore, let Control automatically cache the result SetState2(STATE2_USEPREFERREDSIZECACHE, true); this.dataGridViewState1 = new System.Collections.Specialized.BitVector32(0x00000000); this.dataGridViewState2 = new System.Collections.Specialized.BitVector32(0x00000000); this.dataGridViewOper = new System.Collections.Specialized.BitVector32(0x00000000); this.dataGridViewState1[ DATAGRIDVIEWSTATE1_columnHeadersVisible | DATAGRIDVIEWSTATE1_rowHeadersVisible | DATAGRIDVIEWSTATE1_autoGenerateColumns | DATAGRIDVIEWSTATE1_allowUserToAddRows | DATAGRIDVIEWSTATE1_allowUserToDeleteRows ] = true; this.dataGridViewState2[ DATAGRIDVIEWSTATE2_showEditingIcon | DATAGRIDVIEWSTATE2_enableHeadersVisualStyles | DATAGRIDVIEWSTATE2_mouseEnterExpected | DATAGRIDVIEWSTATE2_allowUserToResizeColumns | DATAGRIDVIEWSTATE2_allowUserToResizeRows | DATAGRIDVIEWSTATE2_showCellToolTips | DATAGRIDVIEWSTATE2_showCellErrors | DATAGRIDVIEWSTATE2_showRowErrors | DATAGRIDVIEWSTATE2_allowHorizontalScrollbar | DATAGRIDVIEWSTATE2_usedFillWeightsDirty ] = true; this.displayedBandsInfo = new DisplayedBandsData(); this.lstRows = new ArrayList(); this.converters = new Hashtable(8); this.pens = new Hashtable(8); this.brushes = new Hashtable(10); this.gridPen = new Pen(DefaultGridColor); this.selectedBandIndexes = new DataGridViewIntLinkedList(); this.individualSelectedCells = new DataGridViewCellLinkedList(); this.individualReadOnlyCells = new DataGridViewCellLinkedList(); this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, DataGridViewAdvancedCellBorderStyle.OutsetDouble, DataGridViewAdvancedCellBorderStyle.OutsetPartial, DataGridViewAdvancedCellBorderStyle.InsetDouble); this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this); this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this); this.advancedCellBorderStyle.All = defaultAdvancedCellBorderStyle; this.advancedRowHeadersBorderStyle.All = defaultAdvancedRowHeadersBorderStyle; this.advancedColumnHeadersBorderStyle.All = defaultAdvancedColumnHeadersBorderStyle; this.borderStyle = defaultBorderStyle; this.dataGridViewState1[DATAGRIDVIEWSTATE1_multiSelect] = true; this.selectionMode = defaultSelectionMode; this.editMode = defaultEditMode; this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing; this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText; this.layout = new LayoutData(); this.layout.TopLeftHeader = Rectangle.Empty; this.layout.ColumnHeaders = Rectangle.Empty; this.layout.RowHeaders = Rectangle.Empty; this.layout.ColumnHeadersVisible = true; this.layout.RowHeadersVisible = true; this.layout.ClientRectangle = this.ClientRectangle; this.scrollBars = ScrollBars.Both; this.horizScrollBar.RightToLeft = RightToLeft.Inherit; this.horizScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccHorizontalScrollBarAccName); this.horizScrollBar.Top = this.ClientRectangle.Height - horizScrollBar.Height; this.horizScrollBar.Left = 0; this.horizScrollBar.Visible = false; this.horizScrollBar.Scroll += new ScrollEventHandler(DataGridViewHScrolled); this.Controls.Add(this.horizScrollBar); this.vertScrollBar.Top = 0; this.vertScrollBar.AccessibleName = SR.GetString(SR.DataGridView_AccVerticalScrollBarAccName); this.vertScrollBar.Left = this.ClientRectangle.Width - vertScrollBar.Width; this.vertScrollBar.Visible = false; this.vertScrollBar.Scroll += new ScrollEventHandler(DataGridViewVScrolled); this.Controls.Add(this.vertScrollBar); this.ptCurrentCell = new Point(-1, -1); this.ptAnchorCell = new Point(-1, -1); this.ptMouseDownCell = new Point(-2, -2); this.ptMouseEnteredCell = new Point(-2, -2); this.ptToolTipCell = new Point(-1, -1); this.ptMouseDownGridCoord = new Point(-1, -1); this.sortOrder = SortOrder.None; this.lastMouseClickInfo.timeStamp = 0; WireScrollBarsEvents(); PerformLayout(); this.toolTipControl = new DataGridViewToolTip(this); Invalidate(); }
public DataGridView () { SetStyle (ControlStyles.Opaque, true); //SetStyle (ControlStyles.UserMouse, true); SetStyle (ControlStyles.OptimizedDoubleBuffer, true); adjustedTopLeftHeaderBorderStyle = new DataGridViewAdvancedBorderStyle(); adjustedTopLeftHeaderBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single; advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(); advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single; advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(); advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single; advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(); advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single; alternatingRowsDefaultCellStyle = new DataGridViewCellStyle(); allowUserToAddRows = true; allowUserToDeleteRows = true; allowUserToOrderColumns = false; allowUserToResizeColumns = true; allowUserToResizeRows = true; autoGenerateColumns = true; autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; backColor = Control.DefaultBackColor; backgroundColor = SystemColors.AppWorkspace; borderStyle = BorderStyle.FixedSingle; cellBorderStyle = DataGridViewCellBorderStyle.Single; clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText; columnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; columnHeadersDefaultCellStyle = new DataGridViewCellStyle(); columnHeadersDefaultCellStyle.BackColor = SystemColors.Control; columnHeadersDefaultCellStyle.ForeColor = SystemColors.WindowText; columnHeadersDefaultCellStyle.SelectionBackColor = SystemColors.Highlight; columnHeadersDefaultCellStyle.SelectionForeColor = SystemColors.HighlightText; columnHeadersDefaultCellStyle.Font = this.Font; columnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; columnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.True; columnHeadersHeight = 23; columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; columnHeadersVisible = true; columns = CreateColumnsInstance(); columns.CollectionChanged += OnColumnCollectionChanged; currentCellAddress = new Point (-1, -1); dataMember = String.Empty; defaultCellStyle = new DataGridViewCellStyle(); defaultCellStyle.BackColor = SystemColors.Window; defaultCellStyle.ForeColor = SystemColors.ControlText; defaultCellStyle.SelectionBackColor = SystemColors.Highlight; defaultCellStyle.SelectionForeColor = SystemColors.HighlightText; defaultCellStyle.Font = this.Font; defaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; defaultCellStyle.WrapMode = DataGridViewTriState.False; editMode = DataGridViewEditMode.EditOnKeystrokeOrF2; firstDisplayedScrollingColumnHiddenWidth = 0; isCurrentCellDirty = false; multiSelect = true; readOnly = false; rowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; rowHeadersDefaultCellStyle = (DataGridViewCellStyle) columnHeadersDefaultCellStyle.Clone (); rowHeadersVisible = true; rowHeadersWidth = 41; rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing; rows = CreateRowsInstance(); rowsDefaultCellStyle = new DataGridViewCellStyle(); selectionMode = DataGridViewSelectionMode.RowHeaderSelect; showCellErrors = true; showEditingIcon = true; scrollBars = ScrollBars.Both; userSetCursor = Cursor.Current; virtualMode = false; horizontalScrollBar = new HScrollBar(); horizontalScrollBar.Scroll += OnHScrollBarScroll; horizontalScrollBar.Visible = false; verticalScrollBar = new VScrollBar(); verticalScrollBar.Scroll += OnVScrollBarScroll; verticalScrollBar.Visible = false; Controls.AddRange (new Control[] {horizontalScrollBar, verticalScrollBar}); }
private void Copy(DataGridViewClipboardCopyMode mode) { this.dgvData.ClipboardCopyMode = mode; Clipboard.SetDataObject(this.dgvData.GetClipboardContent()); }
public DataGridView() { base.SetStyle(ControlStyles.UserMouse | ControlStyles.Opaque | ControlStyles.UserPaint, true); base.SetStyle(ControlStyles.SupportsTransparentBackColor, false); base.SetState2(0x800, true); this.dataGridViewState1 = new BitVector32(0); this.dataGridViewState2 = new BitVector32(0); this.dataGridViewOper = new BitVector32(0); this.dataGridViewState1[0x80001b] = true; this.dataGridViewState2[0x60003e7] = true; this.displayedBandsInfo = new DisplayedBandsData(); this.lstRows = new ArrayList(); this.converters = new Hashtable(8); this.pens = new Hashtable(8); this.brushes = new Hashtable(10); this.gridPen = new Pen(DefaultGridColor); this.selectedBandIndexes = new DataGridViewIntLinkedList(); this.individualSelectedCells = new DataGridViewCellLinkedList(); this.individualReadOnlyCells = new DataGridViewCellLinkedList(); this.advancedCellBorderStyle = new DataGridViewAdvancedBorderStyle(this, DataGridViewAdvancedCellBorderStyle.OutsetDouble, DataGridViewAdvancedCellBorderStyle.OutsetPartial, DataGridViewAdvancedCellBorderStyle.InsetDouble); this.advancedRowHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this); this.advancedColumnHeadersBorderStyle = new DataGridViewAdvancedBorderStyle(this); this.advancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single; this.advancedRowHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial; this.advancedColumnHeadersBorderStyle.All = DataGridViewAdvancedCellBorderStyle.OutsetPartial; this.borderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dataGridViewState1[0x80] = true; this.selectionMode = DataGridViewSelectionMode.RowHeaderSelect; this.editMode = DataGridViewEditMode.EditOnKeystrokeOrF2; this.autoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; this.autoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; this.columnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; this.rowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.EnableResizing; this.clipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText; this.layout = new LayoutData(); this.layout.TopLeftHeader = Rectangle.Empty; this.layout.ColumnHeaders = Rectangle.Empty; this.layout.RowHeaders = Rectangle.Empty; this.layout.ColumnHeadersVisible = true; this.layout.RowHeadersVisible = true; this.layout.ClientRectangle = base.ClientRectangle; this.scrollBars = System.Windows.Forms.ScrollBars.Both; this.horizScrollBar.RightToLeft = RightToLeft.Inherit; this.horizScrollBar.AccessibleName = System.Windows.Forms.SR.GetString("DataGridView_AccHorizontalScrollBarAccName"); this.horizScrollBar.Top = base.ClientRectangle.Height - this.horizScrollBar.Height; this.horizScrollBar.Left = 0; this.horizScrollBar.Visible = false; this.horizScrollBar.Scroll += new ScrollEventHandler(this.DataGridViewHScrolled); base.Controls.Add(this.horizScrollBar); this.vertScrollBar.Top = 0; this.vertScrollBar.AccessibleName = System.Windows.Forms.SR.GetString("DataGridView_AccVerticalScrollBarAccName"); this.vertScrollBar.Left = base.ClientRectangle.Width - this.vertScrollBar.Width; this.vertScrollBar.Visible = false; this.vertScrollBar.Scroll += new ScrollEventHandler(this.DataGridViewVScrolled); base.Controls.Add(this.vertScrollBar); this.ptCurrentCell = new Point(-1, -1); this.ptAnchorCell = new Point(-1, -1); this.ptMouseDownCell = new Point(-2, -2); this.ptMouseEnteredCell = new Point(-2, -2); this.ptToolTipCell = new Point(-1, -1); this.ptMouseDownGridCoord = new Point(-1, -1); this.sortOrder = System.Windows.Forms.SortOrder.None; this.lastMouseClickInfo.timeStamp = 0L; this.WireScrollBarsEvents(); base.PerformLayout(); this.toolTipControl = new DataGridViewToolTip(this); base.Invalidate(); }