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.
Unfortunately, activation email could not send to your email. Please try again.

Copy and Paste including cell style

Thread ID:

Created:

Updated:

Platform:

Replies:

7228 Sep 16,2003 03:00 PM Sep 18,2003 03:22 AM Windows Forms 6
loading
Tags: GridControl
Sue Harris
Asked On September 16, 2003 03:00 PM

Hi, I'd like to include the cell style when I copy and paste data within my virtual grid. I've tried setting the ClipboardFlags and calling CopyCellsToClipboard, but I never seem to get the style information in my SaveCellInfo call, and the data in the clipboard only appears to be text. What do I need to do? Thanks, Sue

Administrator [Syncfusion]
Replied On September 16, 2003 04:17 PM

The grid by default will copy styles. Here is a little sample. If you copy any of the red cells in column 1, and paste them somewhere else, the color is known in SaveCellInfo (though it is not saved by the code in the sample). What is different about what you are trying?

Sue Harris
Replied On September 16, 2003 05:14 PM

> The grid by default will copy styles. Here is a little sample. If you copy any of the red cells in column 1, and paste them somewhere else, the color is known in SaveCellInfo (though it is not saved by the code in the sample). > > What is different about what you are trying? Excellent, your sample let me see whats different. I was trying to copy a single cell (my activate behaviour is double click, so it isn't actually editing), and that seems to use a different copy mechanism (the renderer copy method I presume). Can I modify the copy technique to use the cell copy rather than the render copy, and so copy the style format? Thanks, Sue

Administrator [Syncfusion]
Replied On September 16, 2003 05:45 PM

You can try catching this event and doing the copy yourself in this one-cell case.
private void gridControl1_ClipboardCopy(object sender, GridCutPasteEventArgs e)
{
	if(e.RangeList.Count == 0)
	{
		GridRangeInfoList list = new GridRangeInfoList();
		list.Add(this.gridControl1.CurrentCell.RangeInfo);
		this.gridControl1.CutPaste.CopyCellsToClipboard(list, true);
		e.Handled = true;
		e.Result = true;
	}
}

Sue Harris
Replied On September 16, 2003 06:11 PM

Thanks Clay, That did the trick. My only disappointment was that there wasn't an OnClipboardCopy method in my inheriting control that I could override (I did have to hook the event, rather than override). Thanks, Sue

Sue Harris
Replied On September 17, 2003 09:28 PM

Clay, The copy doesn't appear to be getting the row/column styles. Is this possible? I added the following to the QueryCellInfo method and tried copying and pasting from cells in the second column, and got color [Window] instead of blue. else if ((e.ColIndex == 2) && (e.RowIndex == -1 )) { e.Style.BackColor = Color.Blue; } Thanks, Sue

Administrator [Syncfusion]
Replied On September 18, 2003 03:22 AM

The style is not being composed in the copy code, so you only get the cell attributes. If you look at the source code, there is a //todo section marked to implement a composing styles option but it has not been implemented yet. So for now, if you want the row/col styles to be copied along with the cell style for a cell, you will have to do th process yourself. Below is some code that worked for me.
private void gridControl1_ClipboardCopy(object sender, GridCutPasteEventArgs e)
{
	if(e.RangeList.Count == 0)
	{
		//get a copy of existing cell style
		GridCurrentCell cc = this.gridControl1.CurrentCell;
		GridStyleInfo style = new GridStyleInfo(this.gridControl1[cc.RowIndex, cc.ColIndex]);

		//apply QueryCellInfo row/col attributes
		GridStyleInfo style1 = new GridStyleInfo();
		//row  changes
		this.gridControl1.Model.GetCellInfo(cc.RowIndex, -1, style1);
		style.ModifyStyle(style1, Syncfusion.Styles.StyleModifyType.ApplyNew);
		//col  changes
		this.gridControl1.Model.GetCellInfo(-1, cc.ColIndex, style1);
		style.ModifyStyle(style1, Syncfusion.Styles.StyleModifyType.ApplyNew);
				
		//save the data to the clipboard
		GridData data = new GridData();
		data.RowCount = 1;
		data.ColCount = 1;
		data[0,0] = style.Store;
		Clipboard.SetDataObject(data);
	}
}


CONFIRMATION

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.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;