We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Strange copy/paste behavior in static cells

I'm seeing some strange behavior in cells I've defined as static and read-only. The static cells accept pasted values, but only from other static/read-only cells.

I'm defining the column styles by iterating through a bunch of mapItem (custom class) objects this way:

if (mapItem.ReadOnly || !CanUserEdit)
{
colStyleInfo.ReadOnly = true;
colStyleInfo.BackColor = Color.Gainsboro;
colStyleInfo.CellType = "Static";
}

This is the behavior I'm seeing:

1) If I open the grid and try to copy-paste something from an external application (like notepad) into a read-only cell nothing happens.
2) If I highlight an editable cell in the grid and copy, then try to paste that value into a read-only cell, nothing happens
3) If I highlight a read-only cell and copy, then try to paste into another read-only cell, the copied text is pasted into the destination cell.

I was under the impression that making a cell static and read-only would prevent users from being able to edit the contents, even through pasting.

I could trap the paste event and cancel the paste, but that seems kludgy. Is there some setting I'm missing?

Thanks,

Chris

4 Replies

AD Administrator Syncfusion Team March 6, 2007 05:25 PM UTC

Hi Chris,

If you are pasting data from outside the grid, say excel, then the readonly cell should stop the paste. But if you copying and pasting data from a GridControl, then the default behavior is to copy and paste style information (as opposed to just pasting text from outside the gid). In this case, the readonly setting does not stop the paste.

One simple thing you can do is to turn off the default support for copying styles.

this.gridControl1.CutPaste.ClipboardFlags &= ~GridDragDropFlags.Styles;

If you want to cancel the pasting operation in a static cell then handle the PasteCellText event to cancel it.

this.grid.Model.PasteCellText +=new GridPasteCellTextEventHandler(Model_PasteCellText);
private void Model_PasteCellText(object sender, GridPasteCellTextEventArgs e)
{
if( e.Style.CellType = "Static" )
e.Cancel = true;
}

Best regards,
Haneef


AD Administrator Syncfusion Team March 6, 2007 05:38 PM UTC

Hi Haneef,

Is there any downside to turning off default copy/paste of styles? I'm afraid if i turn that off I'll be creating weird behavior in some other part of the code, and I don't want to play whack-a-mole with bugs all day.

Thanks,

Chris

>Hi Chris,

If you are pasting data from outside the grid, say excel, then the readonly cell should stop the paste. But if you copying and pasting data from a GridControl, then the default behavior is to copy and paste style information (as opposed to just pasting text from outside the gid). In this case, the readonly setting does not stop the paste.

One simple thing you can do is to turn off the default support for copying styles.

this.gridControl1.CutPaste.ClipboardFlags &= ~GridDragDropFlags.Styles;

If you want to cancel the pasting operation in a static cell then handle the PasteCellText event to cancel it.

this.grid.Model.PasteCellText +=new GridPasteCellTextEventHandler(Model_PasteCellText);
private void Model_PasteCellText(object sender, GridPasteCellTextEventArgs e)
{
if( e.Style.CellType = "Static" )
e.Cancel = true;
}

Best regards,
Haneef


CH Chris March 6, 2007 06:36 PM UTC

Alright, now this is very odd.

It DOES fire if:
1) I copy text from an external application and try to paste it into a static cell
2) I copy text from an editable cell in the grid and try to paste it into a static cell in the grid.

It DOESN'T fire if:
3) I copy text from an external application into an editable cell
4) I copy text from a static cell within the grid into another static cell within the grid.

What a weird event. It's particular #4 that's causing me problems. I want to prevent users from pasting ANYTHING into a static cell, no matter where it comes from.

Why is this event so schizo?



AD Administrator Syncfusion Team March 6, 2007 06:56 PM UTC

Hi Chris,

If you want a cell that never changes, then you can subscribe to the SaveCellInfo event, and set e.handled = true for those cells. Below is a snippet that makes Static cells immutable. You can copy and paste them, but the cells themselves cannot be cut or pasted over. Make sure you subscribe to this event after you set the values into the cells (or you values will not be set).

private void gridControl1_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
if( e.Style.CellType == "Static")
e.Handled = true;
}

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon