FlexGrid for WinForms Tutorials > Edit Tutorial > Step 5 of 6: Add Clipboard Support |
The Windows clipboard is a very useful device for transferring information between applications.
Adding clipboard support to FlexGrid for WinForms projects is fairly easy. Simply set the AutoClipboard property to True either in the designer or in code, and the grid will automatically handle all standard keyboard commands related to the clipboard: CTRL+X or SHIFT+DELETE to cut, CTRL+C or CTRL+INSERT to copy, and CTRL+V or SHIFT+INSERT to paste.
Locate the AutoClipboard property in the Properties window and set it to True.
Add the following code after the code added in Step 3 of 6: Incorporate Drop-Down Lists:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
C1FlexGrid1.AutoClipboard = True |
To write code in C#
C# |
Copy Code
|
---|---|
c1FlexGrid1.AutoClipboard = true; |
Another great Windows feature that is closely related to clipboard operations is OLE Drag and Drop. C1FlexGrid has two properties, DragMode and DropMode, which help implement this feature. Just set both properties to their automatic settings either in the designer or in code, and you will be able to drag selections by their edges and drop them into other applications such as Microsoft Excel, or drag ranges from an Excel spreadsheet and drop them into the C1FlexGrid control.
Locate the DragMode and DropMode properties and set them both to Automatic.
Add the following code after the code to set the AutoClipboard property:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
C1FlexGrid1.DragMode = DragModeEnum.Automatic C1FlexGrid1.DropMode = DropModeEnum.Automatic |
To write code in C#
C# |
Copy Code
|
---|---|
c1FlexGrid1.DragMode = DragModeEnum.Automatic; c1FlexGrid1.DropMode = DropModeEnum.Automatic; |
Press F5 to run the project again, then try copying and pasting some data. Note that you can paste invalid data, because our paste code does not perform any data validation. This is left as an exercise for the reader.