Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
9389 | Dec 16,2003 03:56 AM UTC | Dec 17,2003 01:46 AM UTC | WinForms | 4 |
![]() |
Tags: GridControl |
private void gridControl1_ClipboardPaste(object sender, GridCutPasteEventArgs e) { IDataObject data = Clipboard.GetDataObject(); if(data != null && data.GetDataPresent(typeof(string))) { string s = (string)data.GetData(typeof(string)); GridRangeInfoList rangeList; if(this.gridControl1.Selections.GetSelectedRanges(out rangeList, true)) { if(rangeList.ActiveRange.IsCells) { int row = rangeList.ActiveRange.Top; int col = rangeList.ActiveRange.Left; if(this.gridControl1.CurrentCell.IsEditing) this.gridControl1.CurrentCell.CancelEdit(); s = s.Replace("\n", ""); s = s.Replace("\r", ""); this.gridControl1[row, col].Text = s; e.Handled = true; e.Result = true; } } } }
if(this.gridControl1.CurrentCell.IsEditing)
this.gridControl1.CurrentCell.CancelEdit();
If you want to paste the text into an editing currentcell, the get the GridTextBoxControl from the cellrenderer, and set the text there.
if(rangeList.ActiveRange.IsCells) { int row = rangeList.ActiveRange.Top; int col = rangeList.ActiveRange.Left; s = s.Replace("\n", ""); s = s.Replace("\r", ""); if(this.gridControl1.CurrentCell.IsEditing) { GridTextBoxControl tb = this.gridControl1.CurrentCell.Renderer.Control as GridTextBoxControl; if(tb != null) tb.Text = tb.Text.Substring(0, tb.SelectionStart) + s + tb.Text.Substring(0, tb.SelectionStart + tb.SelectionLength ); } else { this.gridControl1[row, col].Text = s; } e.Handled = true; e.Result = true; }
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.