I am new to C# and the UltraGrid.
I want to add a WinForm Copy button that will paste all highlighted grid rows into the current Ultragrid as new rows (I have an identity field column, so, dupes will not be an issue.)
I guess I am just not 'getting' it yet as googling and help searching has not helped. I would have thought this would be such a simple, built in feature that would be easy to find and implement???
2 QUESTIONS:
1) Does anyone have the C# button code that will copy the highlighted grid row(s) and paste into the same grid?
2) Does anyone have the code (or settings) to do the same copy in a Ctlr/C Ctrl/V copy ppaste in the grid?
Watson,You can refer the following help article from Infragistics:http://help.infragistics.com/Help/NetAdvantage/WinForms/2009.1/CLR2.0/html%5CWinGrid_Creating_an_Edit_Menu_with_Clipboard_Operations_for_WinGrid.htmland following code will help you to copy and paste the grid data: private void btnCopy_Click(object sender, System.EventArgs e) { this.UltraGrid1.PerformAction(UltraGridAction.Copy); } private void btnPaste_Click(object sender, System.EventArgs e) { this.UltraGrid1.PerformAction(UltraGridAction.Paste); }Thank you.Bunty :)
Hi,
Bunty_Mishra's suggestion, the ultraGrid.PerformAction(UltraGridAction.Copy) works for me.However, I would also like to determine, if the clipboard has the data of copied rows on it, because I'm enabling/disabling some controls on this condition.
I'm trying to use Clipboard.ContainsData(DataFormat d), which requires the DataFormat to be specified. Can you tell me, which DataFormat I can use for this? Or is there a better way, to achieve this?
Thanks,Richard
Hi Richard,
There's no way to do this as far as I can see. You can use the CurrentState property on the grid to determine if the grid itself is in a state where you can paste by checking for the CanPaste flag.
But the clipboard format is nothing special, it's just string. In theory, I suppose you could examine the string data on the clipboard, but I don't know how you would recognize it as valid for the grid or not. The grid does this, but the code is all internal, so you won't be able to access it.
I recommend that you Submit a feature request to Infragistics. Perhaps the grid methods which validate the clipboard data can be exposed publicly in a future release.