简体   繁体   English

剪贴板访问格式的数据

[英]clipboard accessing data in format

I am doing a copy-paste for the syncfusion grid control. 我正在为syncfusion网格控件复制粘贴。

My question is more abt the paste than abt syncfusion 我的问题更多是abt粘贴而不是abt syncfusion

My data is in datetime-int, datetime-int... format, depending on number of rows,columns selected. 我的数据采用datetime-int,datetime-int ...格式,具体取决于所选的行数和列数。 Here's my code to for the paste 这是我粘贴的代码

private void theGrid_ClipboardPaste(object sender, GridCutPasteEventArgs e)
        {
 DataObject data = (DataObject)Clipboard.GetDataObject();
  try
            {

                if (data.GetDataPresent(DataFormats.Text))
                {
 rowsInClipboard =  stringInClipboard.Split('\n');
                    //split into cellvalues
                     for (int iRow = 0; iRow < rowsInClipboard.Length; iRow++)
                         ValuesInrows = rowsInClipboard[iRow].Split('\t');
...}

How would I validate this data being pasted from the clipboard to the grid. 我将如何验证从剪贴板粘贴到网格的数据。 Would it help if I did a custom format. 如果我做一个自定义格式会有所帮助。 Also I need access the clipboard data based on columns. 我还需要基于列访问剪贴板数据。

Thanks Sun 谢谢孙

You can validate the clipboard data while pasting to grid through event ClipboardCanPaste. 您可以在通过事件ClipboardCanPaste粘贴到网格时验证剪贴板数据。

this.gridControl1.ClipboardCanPaste += new GridCutPasteEventHandler(gridControl1_ClipboardCanPaste); //get triggered before pasting occurs.

If you would like to access the clipboard data to paste to grid across columns, you can split the respective values through a tab key press space in between each illustrating individual cell contents. 如果要访问剪贴板数据以跨列粘贴到网格,则可以通过在每个说明单个单元格内容之间的Tab键按下空格分割各个值。 The following code copies the cell contents across grid cells in the formatted manner to clipboard inorder to make use of this formatted text while pasting from clipboard to any text editor in the column order. 下面的代码以格式化的方式跨网格单元格将单元格内容复制到剪贴板,以便在以列顺序从剪贴板粘贴到任何文本编辑器时使用此格式化的文本。

private void CopyCellsToClipboard(GridRangeInfo range)
{
StringBuilder sb = new StringBuilder();

for (int i = range.Top; i <= range.Bottom; i++)
{
for (int j = range.Left; j <= range.Right; j++)
{
if (! (this.gridControl1.Cols.Hidden[j]))
{
sb.Append(this.gridControl1[i, j].FormattedText);
sb.Append("\t");
}
}
sb.AppendLine(System.Environment.NewLine);
}
string str = sb.ToString().Replace(System.Environment.NewLine + System.Environment.NewLine, System.Environment.NewLine);
DataObject db = new DataObject(DataFormats.UnicodeText, str);
Clipboard.SetDataObject(db);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM